GridView 分页样式

如何能将GridView分页样式做成共[..]条分[..]页[1][2][3][4][5][6][7][8][9][10][>>]的样式,小弟急用,谢谢了... 如何能将GridView 分页样式做成
共[..]条 分[..]页 [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [>>]
的样式,小弟急用,谢谢了
展开
 我来答
yangyaojun2006
推荐于2016-03-16 · 超过34用户采纳过TA的回答
知道小有建树答主
回答量:132
采纳率:0%
帮助的人:0
展开全部
很简单 但要一下说清楚也不好

如果你要用GridView自带的假分页,参照如下代码改下就好

<table width="100%">
<tr>
<td style="text-align:right">
第<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" /><!-- here set the CommandArgument of the Go Button to '-1' as the flag -->
</td>
</tr>
</table>

</PagerTemplate>

protected void grdvSearchResult_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
//this.grdvSearchResult.PageIndex = e.NewPageIndex;
////this.DataBind();

DataTable aaa = new DataTable();
aaa = (DataTable)ViewState["TableForAllSelect"];

grdvSearchResult.DataSource = aaa;
grdvSearchResult.DataBind();
grdvSearchResult.Visible = true;

GridView theGrid = sender as GridView; // refer to the GridView
int newPageIndex = 0;

if (-2 == e.NewPageIndex)
{ // when click the "GO" Button
TextBox txtNewPageIndex = null;
//GridViewRow pagerRow = theGrid.Controls[0].Controls[theGrid.Controls[0].Controls.Count - 1] as GridViewRow; // refer to PagerTemplate
GridViewRow pagerRow = theGrid.BottomPagerRow; //GridView较DataGrid提供了更多的API,获取分页块可以使用BottomPagerRow 或者TopPagerRow,当然还增加了HeaderRow和FooterRow
//updated at 2006年6月21日3:15:33

if (null != pagerRow)
{
txtNewPageIndex = pagerRow.FindControl("txtNewPageIndex") as TextBox; // refer to the TextBox with the NewPageIndex value
}

if (null != txtNewPageIndex)
{
newPageIndex = int.Parse(txtNewPageIndex.Text) - 1; // get the NewPageIndex
}
}
else
{ // when click the first, last, previous and next Button
newPageIndex = e.NewPageIndex;
}

// check to prevent form the NewPageIndex out of the range
newPageIndex = newPageIndex < 0 ? 0 : newPageIndex;
newPageIndex = newPageIndex >= theGrid.PageCount ? theGrid.PageCount - 1 : newPageIndex;

// specify the NewPageIndex
theGrid.PageIndex = newPageIndex;

}
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式