Assume I have templated dropdown list in my gridview (which is bounded to all rows)
The dropdownlist is filled through an array..
//Fill Array
private ArrayList GetDummyData()
{
ArrayList arr = new ArrayList();
arr.Add(new ListItem("Item1", "1"));
arr.Add(new ListItem("Item2", "2"));
arr.Add(new ListItem("Item3", "3"));
return arr;
}
//Fill dropdownlist
private void FillDropDownList(DropDownList ddl)
{
ArrayList arr = GetDummyData();
foreach (ListItem item in arr)
{
ddl.Items.Add(item);
}
}
What I want to do is asssume in gridview row[0] i selected the “Item1”, so in the row[1] there is only 2 options remaining –> “Item2″ and Item3”
Help is much appreciated. 🙂
You could handle the RowDataBound event.
For example(not tested, asssuming the DataSource is a DataTable and the ID of your DropDownList is
ddl):You should consider that this sample won’t work if you’ve paging enabled, because the Rows-property only returns the GridViewRows of the current page.
Edit: Maybe a better approach is to handle the DropDownList’s SelectedIndexChanged event and update the itemlist of any following dropdowns:
Whereas
getDllSourceis following function: