Monday, October 20, 2008

How to iterate through datagrid items with paging ?

Suppose I have one DataGrid with one item column with CheckBox chk_Select. I want

to check the checked record and want to process it.

for (int cnt = 0; cnt < DataGrid.PageCount; cnt++)
{
DataGrid.CurrentPageIndex = cnt;
DataGrid.DataSource=ds;
DataGrid.DataBind();

for (int i = 0; i < DataGrid.Items.Count; i++)
{
CheckBox chk_Select = (CheckBox)DataGrid.Items[i].FindControl("chk_Select");
if (chk_Select.Checked)
{
//Process the row here
}
}
}

No comments: