gridview 自定义分页显示数据处理方法
2009-10-22 15:20
411 查看
自定义gridview分页 ,使显示格式为 :
数据源使用objectdatasource ,页面中代码为:
<asp:GridView ID="GVPigImmuneInfo" runat="server" AllowPaging="True" AutoGenerateColumns="False"
AllowSorting="True" DataSourceID="ods_Immnue" PageSize="16" OnPageIndexChanging="GVPigImmuneInfo_PageIndexChanging">
<PagerTemplate>
<table width="100%">
<tr>
<td style="text-align: center">
第<asp:Label ID="lblPageIndex" runat="server" Text='<%# ((GridView)Container.Parent.Parent).PageIndex + 1 %>' />页
共/<asp:Label ID="lblPageCount" runat="server" Text='<%# ((GridView)Container.Parent.Parent).PageCount %>' />页
<asp:LinkButton ID="btnFirst" runat="server" CausesValidation="False" CommandArgument="First"
CommandName="Page" Text="首页" />
<asp:LinkButton ID="btnPrev" runat="server" CausesValidation="False" CommandArgument="Prev"
CommandName="Page" Text="上一页" />
<asp:LinkButton ID="btnNext" runat="server" CausesValidation="False" CommandArgument="Next"
CommandName="Page" Text="下一页" />
<asp:LinkButton ID="btnLast" runat="server" CausesValidation="False" CommandArgument="Last"
CommandName="Page" Text="尾页" />
<asp:TextBox ID="txtNewPageIndex" runat="server" Width="20px" Text='<%# ((GridView)Container.Parent.Parent).PageIndex + 1 %>' />
<asp:LinkButton ID="btnGo" runat="server" CausesValidation="False" CommandArgument="-1"
CommandName="Page" Text="GO" /><!-- CommandArgument="-1" here set the CommandArgument of the Go Button to '-1' as the flag -->
</td>
</tr>
</table>
</PagerTemplate>
</asp:GridView>
cs 代码文件中的GVPigImmuneInfo_PageIndexChanging处理代码如下:
int page;
if (e.NewPageIndex == -2)
{
GridViewRow pagerRow = GVPigImmuneInfo.BottomPagerRow;
TextBox txtPageNewIndex;
if (null != pagerRow)
{
try
{
txtPageNewIndex = (TextBox)pagerRow.FindControl("txtNewPageIndex");
page = Convert.ToInt32(txtPageNewIndex.Text.Trim()) - 1;
}
catch
{
page = GVPigImmuneInfo.PageIndex;
}
if (page <= 0)
page = 0;
if (page > GVPigImmuneInfo.PageCount)
page = GVPigImmuneInfo.PageCount - 1;
GVPigImmuneInfo.PageIndex = page;// int.Parse(ddlPage.SelectedItem.Text) - 1;
GVPigImmuneInfo.DataBind();
}
}
else
{
if (e.NewPageIndex <= 0)
e.NewPageIndex = 0;
GVPigImmuneInfo.PageIndex = e.NewPageIndex;
GVPigImmuneInfo.DataBind();
}
数据源使用objectdatasource ,页面中代码为:
<asp:GridView ID="GVPigImmuneInfo" runat="server" AllowPaging="True" AutoGenerateColumns="False"
AllowSorting="True" DataSourceID="ods_Immnue" PageSize="16" OnPageIndexChanging="GVPigImmuneInfo_PageIndexChanging">
<PagerTemplate>
<table width="100%">
<tr>
<td style="text-align: center">
第<asp:Label ID="lblPageIndex" runat="server" Text='<%# ((GridView)Container.Parent.Parent).PageIndex + 1 %>' />页
共/<asp:Label ID="lblPageCount" runat="server" Text='<%# ((GridView)Container.Parent.Parent).PageCount %>' />页
<asp:LinkButton ID="btnFirst" runat="server" CausesValidation="False" CommandArgument="First"
CommandName="Page" Text="首页" />
<asp:LinkButton ID="btnPrev" runat="server" CausesValidation="False" CommandArgument="Prev"
CommandName="Page" Text="上一页" />
<asp:LinkButton ID="btnNext" runat="server" CausesValidation="False" CommandArgument="Next"
CommandName="Page" Text="下一页" />
<asp:LinkButton ID="btnLast" runat="server" CausesValidation="False" CommandArgument="Last"
CommandName="Page" Text="尾页" />
<asp:TextBox ID="txtNewPageIndex" runat="server" Width="20px" Text='<%# ((GridView)Container.Parent.Parent).PageIndex + 1 %>' />
<asp:LinkButton ID="btnGo" runat="server" CausesValidation="False" CommandArgument="-1"
CommandName="Page" Text="GO" /><!-- CommandArgument="-1" here set the CommandArgument of the Go Button to '-1' as the flag -->
</td>
</tr>
</table>
</PagerTemplate>
</asp:GridView>
cs 代码文件中的GVPigImmuneInfo_PageIndexChanging处理代码如下:
int page;
if (e.NewPageIndex == -2)
{
GridViewRow pagerRow = GVPigImmuneInfo.BottomPagerRow;
TextBox txtPageNewIndex;
if (null != pagerRow)
{
try
{
txtPageNewIndex = (TextBox)pagerRow.FindControl("txtNewPageIndex");
page = Convert.ToInt32(txtPageNewIndex.Text.Trim()) - 1;
}
catch
{
page = GVPigImmuneInfo.PageIndex;
}
if (page <= 0)
page = 0;
if (page > GVPigImmuneInfo.PageCount)
page = GVPigImmuneInfo.PageCount - 1;
GVPigImmuneInfo.PageIndex = page;// int.Parse(ddlPage.SelectedItem.Text) - 1;
GVPigImmuneInfo.DataBind();
}
}
else
{
if (e.NewPageIndex <= 0)
e.NewPageIndex = 0;
GVPigImmuneInfo.PageIndex = e.NewPageIndex;
GVPigImmuneInfo.DataBind();
}
相关文章推荐
- 对《自定义GridView分页模板中页码Button的实现》中程序的改进,追加显示空行功能
- 对《自定义GridView分页模板中页码Button的实现》中程序的改进,追加显示空行功能
- GridView 始终显示 Pager 分页行的一种方法
- GridView 实现自定义分页、排序、查询、添加、编辑、多选删除、导出、突出显示等常见应用实现
- GridView 实现自定义分页、排序、查询、添加、编辑、多选删除、导出、突出显示等常见应用实现(cs)
- GridView 后台排列 Column 、 用户自定义GridView 显示、GridView的PreRender ,Init,Load 方法
- 对《自定义GridView分页模板中页码Button的实现》中程序的改进,追加显示空行功能
- GridView 实现自定义分页、排序、查询、添加、编辑、多选删除、导出、突出显示等常见应用实现
- ASP.NET GridView自定义分页的方法
- GridView 始终显示 Pager 分页行的一种方法
- GridView分页方法(显示总页数、当前页)
- 海量(大量)数据GridView显示高效率分页实现方法
- ASP.NET GridView自定义分页的方法
- 自定义GridView分页模板
- C#自定义分页方法一
- 分页解决方案 之 QuickPager的使用方法(PostBack分页、自定义获取数据)
- 自定义安装 Python 后,出现方向键无法用,按下方向键后,终端显示的式相应的字符编码,而不是方向键的功能的解决方法
- Sencha Touch2.3.1中自定义Ext.Msg中按钮显示信息方法
- GridView 自定义分页
- onethink后台添加自定义菜单不显示的解决方法(转)