views:

76

answers:

0

Basically when editing an item, I want to bind its ProviderId value to the DropDownList's select value. DropDownList is getting its list of values from other entity 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-behind:

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();
}