how to bind dropdownlist which is inside repeater?

Ram Singh picture Ram Singh · Sep 12, 2011 · Viewed 33.7k times · Source

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>

Answer

Guilherme de Jesus Santos picture Guilherme de Jesus Santos · Sep 12, 2011

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

}