Ram Singh Ram Singh - 2 days ago 7
ASP.NET (C#) Question

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>

Answer

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

}
Comments