raphael232
Programmer
Hi, i'm having problems binding to the DropDownList control. Here's my code:
and here's my code behind (Page_Load event handler):
When i run the application i get the error:
'lstCategoryID' has a SelectedValue which is invalid because it does not exist in the list of items.
Parameter name: value
This seems a strange error since there is a value in the DropDownList which is the same as the value i am trying to bind to. I think it might be something to do with me loading in the contents of the DropDownList with the Page_Load event handler (since i have had no problems with dropdownlists with static options). I have also tried putting in the Page_Init event handler but this did not work either.
Appreciate if someone could help. Thanks
Code:
<asp:DropDownList ID="lstCategoryID" SelectedValue='<%# Eval("CategoryID") %>' DataTextField="Text" DataValueField="Value" runat="server">
</asp:DropDownList>
and here's my code behind (Page_Load event handler):
Code:
Dim lstCategoryID As DropDownList = CType(FormView1.FindControl("lstCategoryID"), DropDownList)
lstCategoryID.DataSource = Utilities.GetCategoriesList()
lstCategoryID.DataBind()
When i run the application i get the error:
'lstCategoryID' has a SelectedValue which is invalid because it does not exist in the list of items.
Parameter name: value
This seems a strange error since there is a value in the DropDownList which is the same as the value i am trying to bind to. I think it might be something to do with me loading in the contents of the DropDownList with the Page_Load event handler (since i have had no problems with dropdownlists with static options). I have also tried putting in the Page_Init event handler but this did not work either.
Appreciate if someone could help. Thanks