您的位置:首页 > 其它

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();
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐