Snap to ASP.NET DropDownList in ListView

Basically when editing an element, I want to bind its ProviderId value to the DropDownList selection value. DropDownList gets its list of values โ€‹โ€‹from another entity_List , as you can see.

Markup:

 <asp:ListView ID="aList" runat="server" OnDataBound="aList_OnDataBound" DataKeyNames="ListServID" DataSourceID="ListServCon" InsertItemPosition="LastItem" selectedvalue='<%# Bind("ProviderID") %>' > <EditItemTemplate> <asp:DropDownList ID="ddlist" runat="server" Width="155px" AutoPostBack="true" SelectedValue='<%# Bind("ProviderID") %>' /> </EditItemTemplate> </asp:ListView> 

Code for:

 if (aList.EditItem != null) { DropDownList ddlist_temp = (DropDownList)aList.EditItem.FindControl("ddlist"); ddlist_temp.DataSource = entity_List; ddlist_temp.DataTextField = "ShowText"; ddlist_temp.DataValueField = "ID"; ddlist_temp.DataBind(); } 
+2
drop-down-menu data-binding listview
source share
1 answer

If SelectedValue is a ProviderId, this should not be:

 ddlist_temp.DataValueField = "ProviderID"; 
0
source share

All Articles