Hi i have a FormView control with a DropDownList in like so:
<aspropDownList ID="lstCategoryID" DataTextField="Text" DataValueField="Value" runat="server">
</aspropDownList>
And in the Page_Load event handler i have the following:
Dim lstCategoryID As DropDownList = CType(FormView1.FindControl("lstCategoryID"), DropDownList)
lstCategoryID.DataSource = Utilities.GetCategoriesList(_sectionID, 0, "")
lstCategoryID.DataBind()
Which populates the DropDownList fine but i need to select the appropriate value based on the CategoryID for the item i am editing.
I tried putting SelectedValue='<%# Eval("CategoryID") %>' on the dropdownlist but it returned the following error.
"'lstCategoryID' has a SelectedValue which is invalid because it does not exist in the list of items"
The trouble is the value for CategoryID is the item i am editing is in the DropDownList. I have had no problem in the past when the DropDownList was statically populated. Therefore i think the problem might be that i am binding the data in the code behind file but i don't know how to solve it.
Appreciate your help. Thanks
<aspropDownList ID="lstCategoryID" DataTextField="Text" DataValueField="Value" runat="server">
</aspropDownList>
And in the Page_Load event handler i have the following:
Dim lstCategoryID As DropDownList = CType(FormView1.FindControl("lstCategoryID"), DropDownList)
lstCategoryID.DataSource = Utilities.GetCategoriesList(_sectionID, 0, "")
lstCategoryID.DataBind()
Which populates the DropDownList fine but i need to select the appropriate value based on the CategoryID for the item i am editing.
I tried putting SelectedValue='<%# Eval("CategoryID") %>' on the dropdownlist but it returned the following error.
"'lstCategoryID' has a SelectedValue which is invalid because it does not exist in the list of items"
The trouble is the value for CategoryID is the item i am editing is in the DropDownList. I have had no problem in the past when the DropDownList was statically populated. Therefore i think the problem might be that i am binding the data in the code behind file but i don't know how to solve it.
Appreciate your help. Thanks