Quantcast
Channel: Web Forms
Viewing all articles
Browse latest Browse all 23244

Unable to assign value to dropdownlist

$
0
0

I am using class dropdownlist derived from system.web.ui.webcontrols.dropdownlist

I adding option "--select--" on databound event using below code

if (NeedSelect)
                {
                    if (!this.Items.Contains(new ListItem("--Select--", "0")))
                        this.Items.Insert(0, new ListItem("--Select--", "0"));
                }

I have insert same selectedvalue property also (before assigning value )

if (value!=null && this.Items.FindByValue(value.Trim()) != null && Items.Count>0)
{
base.SelectedValue = value.Trim();
}
else
{
	base.SelectedIndex = -1;
}

but when assign the value 0 for option "--select--" to selected value for editing a grid view record, the following error occurs.

<controlName> has a SelectedValue which is invalid because it does not exist in the list of items.\r\nParameter name: value

Please help me very urgent.

Darani




Viewing all articles
Browse latest Browse all 23244

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>