| Profiel van Radu-CristianRaducu's blogFoto'sWeblogLijsten | Help |
|
15 september DropDownList data binding BUG Today I've spent more than one hour trying to solve the following issue: I have a DropDownList control and I bind a collection of objects and then I set the SelectedValue to the first value from the collection. Here is the piece of code I've used:
ddlControl.DataSource = myCollection;
ddlControl.DataTextField = "Text";
ddlControl.DataValueField = "Value"; ddlControl.DataBind();
ddlControl.SelectedValue = "1";
Everything was fine, but when I tried to rebind the same control to another collection of the same objects (a subcollection), I got the following error:
'ddControll' has a SelectedValue which is invalid because it does not exist in the list of items. Parameter name: value.
This is a BUG and I solved this issue by replacing the code with a foreach statement and I added manually each item to the collection of Items.
ddlControl.Items.Clear();
foreach (Item item in items) { ddlControl.Items.Add(new ListItem(item.Text, item.Value)); } ddlControl.SelectedValue = "0"; (3) reactiesMeld je aan bij Windows Live ID om een reactie toe te voegen (als je Hotmail, Messenger of Xbox LIVE gebruikt, heb je al een Windows Live ID). Aanmelden Heb je geen Windows Live ID? Maak er nu een aan
Links naar je weblogDe URL voor de link naar dit weblogitem is: http://alexaraducristian.spaces.live.com/blog/cns!97400EE604B4E02D!161.trak Weblogs die naar dit item verwijzen
|
|
|