这是表格的设置信息
<f:Grid ID="Grid2" Title="表格" EnableCollapse="true" PageSize="5" ShowBorder="true" ShowHeader="true" IsDatabasePaging="true" AllowPaging="true" ShowPagingMessage="true"
runat="server" EnableCheckBoxSelect="false" Width="1000px" Height="300" DataKeyNames="ID,city,county,street,village,reporter,reportUnit,operType,operTime,checked,remark"
EnableRowDoubleClickEvent="true" >
在OnPageIndexChange对应的AddressReportGrid_PageIndexChange方法里面的Grid2.pageIndex 一直为0,我是按照在线的代码的思路设计的。
主要的方法几乎没改动
public void AddressReportGrid_PageIndexChange(object sender, EventArgs e)
{
Alert.Show(Grid2.PageIndex.ToString());
AddressReportGridBind();
}
public void AddressReportGridBind()
{
Grid2.RecordCount = reportTable.Rows.Count;
DataTable table = GetReportGridPagedDataTable(Grid2.PageIndex, Grid2.PageSize);
//绑定到Grid
Grid2.DataSource = table;
Grid2.DataBind();
}
public DataTable GetReportGridPagedDataTable(int pageIndex, int pageSize)
{
DataTable source = reportTable;
DataTable paged = source.Clone();
int rowbegin = pageIndex * pageSize;
int rowend = (pageIndex + 1) * pageSize;
if (rowend > source.Rows.Count)
{
rowend = source.Rows.Count;
}
for (int i = rowbegin; i < rowend; i++)
{
paged.ImportRow(source.Rows[i]);
}
return paged;
}
|