Gridview asp.net中的分页计数 [英] Pagin count in Gridview asp.net
问题描述
亲爱的所有人,
正在使用asp.net,c#,SqlServer2005.
我有一个Gridview充满了成千上万的记录.而且我也为此做了分页.
就像1 2 3 4 5 6 7 8 9 10 ........... 500
现在我的要求是当用户单击第2页时.
在gridview下方,它必须显示标签消息您正在查看第2页(共100页).
我需要通过编码来实现.
请帮忙
永远感谢.
Dear All,
am working on asp.net ,c#,SqlServer2005.
I have a Gridview filled with thousands of records. and also i did paging for it.
just like 1 2 3 4 5 6 7 8 9 10...........500
Now my requirement is when the user clicks on page 2.
below gridview it must show a label message "you are viewing page 2 of 100.
i need this by coding.
Please help
Thanks for ever.
推荐答案
在此示例中,我将"ProductInfo"类用于GridView数据源,将"dtgView"用于我的GridView,将"lblPageInfo标签"用于显示页面信息.您需要GridView AllowPaging ="True"并生成OnPageIndexChanging ="dtgView_PageIndexChanging"事件以分页GridView. br/>
然后需要在页面上将GridView绑定到下面的代码中:
here an example i use "ProductInfo" class for GridView DataSource, "dtgView" my GridView and "lblPageInfo Label for display page information. You need to GridView AllowPaging="True" and generate OnPageIndexChanging="dtgView_PageIndexChanging" Event for paging your GridView.
then need to Bind GridView on page load code below:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
List<productinfo> list = new ProductInfo().SelectAll4Grid();
// Collection of Product.
dtgView.DataSource = list;
dtgView.DataBind();
lblPageInfo.Text = "you are viewing page 1 of " + dtgView.PageCount.ToString();
// Display Page Information.
}
}
</productinfo>
那么您需要在页面索引更改事件上绑定GridView并在下面收集您的页面信息代码:
then you need to Bind GridView on page index changing event and collect your page information code below:
protected void dtgView_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
List<productinfo> list = new ProductInfo().SelectAll4Grid();
dtgView.PageIndex = e.NewPageIndex;
lblPageInfo.Text = "you are viewing page " + (e.NewPageIndex + 1).ToString() + " of " + dtgView.PageCount.ToString();
// Page Index Start from 0 so we need +1
dtgView.DataSource = list;
dtgView.DataBind();
}
</productinfo>
它正在我的项目上.尝试使用它.
it''s working on my project. try use it.
这篇关于Gridview asp.net中的分页计数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!