开发者

How to loop through all items in the grid when paging property for grid is set

开发者 https://www.devze.com 2023-03-31 00:01 出处:网络
I have grid where i am setting the page size as 14 ,and my gr开发者_StackOverflowid contains 56 items, when i trying to loop through the grid items it considers only the first page 14 items and comes

I have grid where i am setting the page size as 14 ,and my gr开发者_StackOverflowid contains 56 items, when i trying to loop through the grid items it considers only the first page 14 items and comes out of the loop, but i want rest of the items also , please can any one help me to solve this problem.

if (AvailableRolesGrid.Items.Count != 0)
                {
                    foreach (GridDataItem availablerole in AvailableRolesGrid.Items)
                    {
                       //

}
}


One option would be to use the DataSource, like this:

DataTable table = (DataTable)DataGrid1.DataSource;
if (table != null)
{
     foreach (DataRow row in table.Rows)
     {
          string roleName = row.Field<string>("RoleName");
     }
}

This is probably better actually, because it will be easier to access the data. Doing it through the grid, you'll have to pull the values from the cells, which would be a pain.


If you are binding to the grid, why not use the dataset or datatable you binded to the grid and loop through it. It has all the recordsets that were returned from your datasource. Since it is binded to your grid whatever changes you make to it will reflect in the grid.

0

精彩评论

暂无评论...
验证码 换一张
取 消