无法使用DataPager从Rad Grid-View获取所有行

时间:2013-12-18 12:08:27

标签: c# asp.net datagridview telerik radgrid

这是我的dataGridView,

 <telerik:RadGrid ID="grdSalaryCalculation" runat="server" AllowPaging="True" AutoGenerateColumns="False"
                    Skin="Telerik" Font-Names="Myanmar3" CellSpacing="0" EnableLinqExpressions="False"
                    OnNeedDataSource="grdSalaryCalculation_NeedDataSource" GridLines="None" ShowFooter="True"
                    PageSize="5" AllowSorting="true" OnItemDataBound="grdSalaryCalculation_ItemDataBound">
                    <ExportSettings ExportOnlyData="True" FileName="Attendance List">
                    </ExportSettings>
                    <GroupingSettings CaseSensitive="false"></GroupingSettings>
                    <MasterTableView DataKeyNames="EmpID,NRC" CommandItemDisplay="Top" AllowFilteringByColumn="true"
                        HeaderStyle-HorizontalAlign="Center" EnableHeaderContextMenu="true" EnableHeaderContextFilterMenu="true"
                        IsFilterItemExpanded="false" AllowSorting="true">
                        <CommandItemSettings ShowAddNewRecordButton="false" ShowExportToExcelButton="true">
                        </CommandItemSettings>
                        <RowIndicatorColumn Visible="True" FilterControlAltText="Filter RowIndicator column">
                            <HeaderStyle Width="20px"></HeaderStyle>
                        </RowIndicatorColumn>
                        <ExpandCollapseColumn Visible="True" FilterControlAltText="Filter ExpandColumn column">
                            <HeaderStyle Width="20px"></HeaderStyle>
                        </ExpandCollapseColumn>
                        <Columns>
                        ......
                        ......

这就是我循环dataRow并获取

的方式
        foreach (GridDataItem dataItem in grdSalaryCalculation.MasterTableView.Items)
        {

我的GridView有大约20行,但我使用了PageSize=5 使用上面的代码,我只能获得5行 如何从GridView获取所有行(20行)?

1 个答案:

答案 0 :(得分:2)

已修复!
使用this链接,只需在循环开始和结束时添加AllowPaging=false and true即可。

RadGrid1.AllowPaging = false;
RadGrid1.Rebind();

        foreach (GridDataItem item in RadGrid1.MasterTableView.Items)
        {

        }

RadGrid1.AllowPaging = true;
RadGrid1.Rebind();

此代码可以通过Paging从Data GridView获取所有行!