Click to See Complete Forum and Search --> : Drop Down List + Static Items + Selecting Databound


Evie
03-10-2009, 11:32 AM
Hi guys,

I have a page that has:

* GridView
* DetailsView based on GridView selection

In the Edit of the DetailsView, I want to have a dropdown that has existing values and have the selected value be the one from the Data Entry (if that makes sense)

For Example. The selection has a Dialer value of "Tsp1"

in Edit, I want:

"Cor"
"Mon"
"Tsp1"
"Tsp2"

but I want "Tsp1" to be the value selected.

I am using C# code-behind btw.

Thanks in advance.

JoeyD
03-29-2009, 09:54 PM
I think you would need something like this:

string valueToGet = ((controltype)gridviewID.FindControl("ControlID")).ValueProperty;
DropDownList ddl = ((DropDownList)detailsViewID.FindControl("DropDownListID));

ListItem lst = ddl.Items.FindByText(valueToGet);
if (lst != null) {
ddl.selectedIndex = -1;
lst.selected = true;
}

Set the index of the dropdownlist to -1 first or you might get a can't select multiple items error