开发者

Databinding to ASP.NET DropDownList list in ListView

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 = enti开发者_开发技巧ty_List;
    ddlist_temp.DataTextField = "ShowText";
    ddlist_temp.DataValueField = "ID";
    ddlist_temp.DataBind();
}


If the SelectedValue is ProviderId, shouldn't this be:

ddlist_temp.DataValueField = "ProviderID";
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜