asp.net GridView分页中页脚如何加上当前页和总页数
4个回答
展开全部
参照如下代码改下html样式就好 ,不明白的留言我
<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;
}
<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;
}
展开全部
GridView分页中,一般有两种数据读取方式:
第一种是一次性把所要的数据全部读到客户端,再进行处理,如比放到datatable中,总页数就是datatable["表名"].rows.count/每页的数据条数.但这种方式不适合大数据量查询,特别是在多人一起查询时.
第二种方式也是本人常用的方法,使用SQL中的row_number()函数,就是读取我当前页的数据.比如:
select * from (select row_number() over(order by siteid desc) as rowNumber,* from 表名 ) as table1 where rowNumber between (本页起始条数,如:20) and (本页结束条数,如40) order by inid desc
得到的数据直接输出到GridView则可以了!
第一种是一次性把所要的数据全部读到客户端,再进行处理,如比放到datatable中,总页数就是datatable["表名"].rows.count/每页的数据条数.但这种方式不适合大数据量查询,特别是在多人一起查询时.
第二种方式也是本人常用的方法,使用SQL中的row_number()函数,就是读取我当前页的数据.比如:
select * from (select row_number() over(order by siteid desc) as rowNumber,* from 表名 ) as table1 where rowNumber between (本页起始条数,如:20) and (本页结束条数,如40) order by inid desc
得到的数据直接输出到GridView则可以了!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
当前页:GridView1.PageIndex
总页数:GridView1.PageCount
用一个lable显示就行啦。后台在对gridview绑定数据后 输出以上属性。
lblCount.Text = "总共" + ds.Tables[0].Rows.Count.ToString() + "条数据";
lblPage.Text = "第" + (gvChanpin.PageIndex + 1).ToString() + "页";
lblPageCount.Text = "共" + gvChanpin.PageCount.ToString() + "页";
总页数:GridView1.PageCount
用一个lable显示就行啦。后台在对gridview绑定数据后 输出以上属性。
lblCount.Text = "总共" + ds.Tables[0].Rows.Count.ToString() + "条数据";
lblPage.Text = "第" + (gvChanpin.PageIndex + 1).ToString() + "页";
lblPageCount.Text = "共" + gvChanpin.PageCount.ToString() + "页";
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
有dll文件的
可以直接用的
前台需要,算数据有多少的
然后生成<a>放lbl里
可以直接用的
前台需要,算数据有多少的
然后生成<a>放lbl里
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询