Click here to Skip to main content
15,998,694 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hello sir, i am using repeator in asp.net .
i want to bind data in dropdownlist inside repeator when i click another dropdownlist then lie outside repeator.
Sir how to do this.
Send me code sir.
Posted
Comments
Sinisa Hajnal 28-Sep-15 5:57am    
You don't get finished code here, this is not free code service. What you can do is describe what you need, what you did and what doesn't work as you expect it to. Then someone here takes a look and suggests the solution.

1 solution

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
LoadDropDown1();
LoadRepeater();
}
}

private void LoadRepeater()
{
List<int> items = new List<int>() { 1, 2, 3, 4, 5 };
Repeater1.DataSource = items;
Repeater1.DataBind();
}

private void LoadDropDown1()
{
Dictionary<int,> listOfData = new Dictionary<int,>();
listOfData.Add(1, "Item1");
listOfData.Add(2, "Item2");
listOfData.Add(3, "Item3");
listOfData.Add(4, "Item4");

FillDropDownList(ref ddl1, listOfData);
}

private void FillDropDownList(ref DropDownList ddl, Dictionary<int,> data)
{
ddl.DataSource = data;
ddl.DataTextField = "Value";
ddl.DataValueField = "Key";
ddl.DataBind();
}

protected void ddl1_SelectedIndexChanged(object sender, EventArgs e)
{
LoadRepeater();
}

protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
DropDownList ddl2 = e.Item.FindControl("ddl2") as DropDownList;

Dictionary<int,> listOfData = new Dictionary<int,>();
listOfData.Add(1, "Item1");
listOfData.Add(2, "Item2");
listOfData.Add(3, "Item3");
listOfData.Add(4, "Item4");

FillDropDownList(ref ddl2, listOfData);
}
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900