Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to loop through all the rows in foreach. I tried following two ways, but nothing is working.

First Solution GridView1.Rows getting Zero. In this step if i put GridView1.DataBind(), then Gridview is getting Invisible.

Second Solution, looping all the rows and all the pages but the next page checkbox value is also showing the first page last row checkbox value.
C#
GridView1.AllowPaging = false;
GridView1.DataBind();
 
foreach (GridViewRow item in GridView1.Rows)
{
    CheckBox chkBox = (CheckBox)item.FindControl("cbstrChild");
 
    ..............
 
}
 
GridView1.AllowPaging = true;
GridView1.DataBind();

==============================
C#
for (int i = 0; i <gridview1.pagecount;>{
    GridView1.PageIndex = i;
    foreach (GridViewRow item in GridView1.Rows)
    {
        CheckBox chkBox = (CheckBox)item.FindControl("chkBxSelect");

        if (chkBox.Checked)
        {
           ...
        }
    }
}
Posted
Updated 21-May-12 22:14pm
v3

1 solution

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