I have nested asp repeaters

<asp:repeater id="ParentRepeater" runat="server" OnItemDataBound="repMenu1_ItemDataBound">  
    <itemtemplate>  
        <table>  
            <tr>  
                <td>  
                    <asp:CheckBox id="CheckBox1" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"DESCRIPTION") %>' OnCheckedChanged="chkBox_CheckedChanged" >  
                    </asp:CheckBox>  
                </td>  
            </tr>  
            <tr>  
                <td>  
                    <!-- start child repeater -->  
                    <asp:repeater id="childRepeater" runat="server">  
                        <itemtemplate>  
                            <TABLE id="Table1" border="0" cellSpacing="0" cellPadding="0" width="1000">  
                                <TR>  
                                    <TD><%# DataBinder.Eval(Container.DataItem,"Trx") %></TD>  
                                    <TD><%# DataBinder.Eval(Container.DataItem,"GL") %></TD>  
                                    <TD><%# DataBinder.Eval(Container.DataItem,"Amount") %></TD>  
                                </TR>  
                            </TABLE>  
                        </itemtemplate>  
                    </asp:repeater>  
                    <!-- end child repeater -->  
                </td>  
            </tr>  
            <tr>  
            </tr>  
        </table>  
    </itemtemplate>  
</asp:repeater>

I use if(! Page.postback) to fill those two repeaters

I want to get the data related to checked checkboxes when using the below code it get only the data of the first checked box

how to make it brign all the data

private void Btn_Confirm_Click(object sender, System.EventArgs e)
{
//CheckBox checkedButton = null; 


foreach (RepeaterItem item in ParentRepeater.Items) 
{ 

CheckBox control=(CheckBox)item.FindControl("CheckBox1"); 
if (control.Checked) 
{ 
//checkedButton = control; 

foreach(DataRow r in GetInnerData(control.Text).Rows  )   // GetInnerData is used to pring datarelated to the selected check box 
{
if(r["DESCRIPTION"].ToString() == control.Text)
{
Response.Write(r["DESCRIPTION"].ToString() + r["Date" ].ToString() + r[ "Trx" ].ToString() + r[ "GL" ].ToString() +  r["Amount" ].ToString() +"\n");


}

Dani AI

Generated

Summary and focused fixes (short checklist)

The symptom you describe (only the first checked item producing rows) almost always comes from one of three things: relying on the CheckBox.Text as the unique key, mixing up the ASP.NET page lifecycle (re-binding at the wrong time), or writing output with plain "\n" so later lines are not visible in HTML. Below are concrete, minimal fixes you can apply quickly.

Use a stable key (do not rely on Text)

  • Put a server HiddenField (or a data key) inside the parent item template and bind the row PK there. Use that value when calling GetInnerData rather than CheckBox.Text.

Example (add to the parent ItemTemplate)

<asp:HiddenField ID="hfKey" runat="server" Value='<%# Eval("ID") %>' />

Handle binding and postbacks correctly

  • Keep ParentRepeater bound in Page_Load only when !IsPostBack to preserve user selections.
  • Bind childRepeater inside ParentRepeater_ItemDataBound so the nested rows are created from the server data when the parent is bound.
  • In your button handler, either (A) read the HiddenField/ID and call GetInnerDataById(id) for each checked parent row, or (B) iterate the childRepeater.Items in the same parent item (if you need the already-bound nested rows).

Render results safely (do not rely on "\n")

  • Build a string or use a Literal/Label and insert "<br/>" between rows so output is visible in the browser.

Minimal server-side pattern (use a for-loop to avoid accidental reuse of a single variable)

var sb = new System.Text.StringBuilder();
for (int i = 0; i < ParentRepeater.Items.Count; i++)
{
    var parent = ParentRepeater.Items[i];
    var chk = parent.FindControl("CheckBox1") as CheckBox;
    var hf = parent.FindControl("hfKey") as HiddenField;
    if (chk != null && chk.Checked && hf != null)
    {
        var dt = GetInnerDataById(hf.Value); // pass the key, not the label text
        foreach (System.Data.DataRow r in dt.Rows)
        {
            sb.AppendFormat("{0} {1} {2} {3} {4}<br/>",
                            r["DESCRIPTION"], r["Date"], r["Trx"], r["GL"], r["Amount"]);
        }
    }
}
resultLiteral.Text = sb.ToString();

Notes tied to thread:

  • was right to suggest an inner loop, but make sure you loop the correct data set (childRepeater.Items or GetInnerDataById) for each checked parent row.
  • pointed at IsPostBack — confirm you are using the exact property name IsPostBack and not a misspelled variant.

If this still returns only one parent, verify GetInnerDataById actually returns all matching rows for each distinct key and that you are not inadvertently re-binding the parent repeater before processing the button click (which wipes selections).

Recommended Answers

All 2 Replies

I have nested asp repeaters

<asp:repeater id="ParentRepeater" runat="server" OnItemDataBound="repMenu1_ItemDataBound">  
    <itemtemplate>  
        <table>  
            <tr>  
                <td>  
                    <asp:CheckBox id="CheckBox1" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"DESCRIPTION") %>' OnCheckedChanged="chkBox_CheckedChanged" >  
                    </asp:CheckBox>  
                </td>  
            </tr>  
            <tr>  
                <td>  
                    <!-- start child repeater -->  
                    <asp:repeater id="childRepeater" runat="server">  
                        <itemtemplate>  
                            <TABLE id="Table1" border="0" cellSpacing="0" cellPadding="0" width="1000">  
                                <TR>  
                                    <TD><%# DataBinder.Eval(Container.DataItem,"Trx") %></TD>  
                                    <TD><%# DataBinder.Eval(Container.DataItem,"GL") %></TD>  
                                    <TD><%# DataBinder.Eval(Container.DataItem,"Amount") %></TD>  
                                </TR>  
                            </TABLE>  
                        </itemtemplate>  
                    </asp:repeater>  
                    <!-- end child repeater -->  
                </td>  
            </tr>  
            <tr>  
            </tr>  
        </table>  
    </itemtemplate>  
</asp:repeater>

I use if(! Page.postback) to fill those two repeaters

I want to get the data related to checked checkboxes when using the below code it get only the data of the first checked box

how to make it brign all the data

private void Btn_Confirm_Click(object sender, System.EventArgs e)
{
//CheckBox checkedButton = null; 


foreach (RepeaterItem item in ParentRepeater.Items) 
{ 

CheckBox control=(CheckBox)item.FindControl("CheckBox1"); 
if (control.Checked) 
{ 
//checkedButton = control; 

foreach(DataRow r in GetInnerData(control.Text).Rows  )   // GetInnerData is used to pring datarelated to the selected check box 
{
if(r["DESCRIPTION"].ToString() == control.Text)
{
Response.Write(r["DESCRIPTION"].ToString() + r["Date" ].ToString() + r[ "Trx" ].ToString() + r[ "GL" ].ToString() +  r["Amount" ].ToString() +"\n");


}

Hi there

you need another loop inside parent repeater

foreach(DataRow r in GetInnerData(control.Text).Rows  )   
{
      //foreach(DataRow r in .....
          { //do your stufff

Mark as solved if it helps you!!!

u can try this with the method

if(!Ispostback)
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.