Click here to Skip to main content
15,888,454 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
How to give the DataTextField and DatavalueField for a CheckBoxList nested inside a Repeater?

My repeater control is given below..but it is not working..please help me
XML
<asp:Repeater runat="server" ID="rptCategories">
    <HeaderTemplate>
     </HeaderTemplate>
    <itemtemplate>
    <asp:CheckBoxList ID="CheckBoxList1" runat="server" DataSource='<%# ((System.Data.DataRowView)Container.DataItem).Row.GetChildRows("CategoryToMenu") %>' DataTextField='<%# DataBinder.Eval(Container.DataItem, "[\"ItemName\"]")%>' >
               < /itemtemplate>
</asp:Repeater>
Posted
v3

1 solution

Use the ItemDataBound event of the Repeater, like this:

C#
protected void rep_Comps_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
    CheckBoxList chkList = e.Item.FindControl("chk_chkbx") as CheckBoxList ;
    if (selectList != null)
    {
        chkList.DataSource = SomeDataSource();
        chkList.DataBind();

        chkList.DataTextField = "SomeColumn";
       chkList.DataValueField = "SomeID";
    }
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900