Search code examples
asp.netdrop-down-menurepeater

how to bind dropdownlist which is inside repeater?


I want to bind dropdownlist which is inside a repeater.my code is

 <asp:Repeater ID="rep_UnAssignComps" runat="server">
    <ItemTemplate><asp:DropDownList ID="drp_CompPropAddress" runat="server">
            </asp:DropDownList></itemTemplate></asp:Repeater>

Solution

  • On your Repeater's ItemDatabound event use the following:

    if (e.Item.ItemType == ListItemType.Item || 
             e.Item.ItemType == ListItemType.AlternatingItem)
    {
    
        ((DropDownList)e.Item.FindControl("drp_CompPropAddress")).DataSource =(DataRowView) e.Item.DataItem;//Or any other datasource.
        ((DropDownList)e.Item.FindControl("drp_CompPropAddress")).DataBind();
    
    }