ASP.NET 2.0 DropDownList - FindByText / FindByValue
Assuming you want to achieve this:
1 GridView with 2 columns of databoundfield. There is 1 buttonfield called Edit with a command “UpdateThis”. When you click on Edit, it will open an input panel and shows 2 dropdown list controls. The 1st dropdown list has 5 items inside. The 2nd one has 10 items inside. From the gridview’s values selected, you need to dynamic pass the values into the dropdownlist while maintaining the state of it. How can you do that?
If you try to do this, you will not achieve the desire results:
ddlProgramOwnerDivisionName.SelectedItem.Text = dropdownValue;
By doing that, it will overwrite existing items. Not a good idea at all. Try this instead; you can either set FindByText or FindByValue.
ddlList1.SelectedIndex = ddlList1.Items.IndexOf(ddlList1.Items.FindByText(dropdownText));
Or
ddlList1.SelectedIndex = ddlList1.Items.IndexOf(ddlList1.Items.FindByValue(dropdownValue));
Have fun.