[英]how to achieve paging in a grid view in code
I'm using ASP.net web application with c#. 我正在将ASP.net Web应用程序与c#一起使用。 In my web application I have a webpage with a data grid view.
在我的Web应用程序中,我有一个带有数据网格视图的网页。
I'm using this method to bind data to data grid view 我正在使用这种方法将数据绑定到数据网格视图
public void fillGridByALLBDetails()
{
GVView01.DataSource = new LibraryCatalogueOP().getLibraryCatalogue();
GVView01.DataBind();
}
I'm calling the data grid view bind method in the page load event like this. 我在这样的页面加载事件中调用数据网格视图绑定方法。
if (!IsPostBack)
{
fillGridByALLBDetails();
}
This is my business layer method to get the data. 这是我的业务层方法来获取数据。
public DataTable getLibraryCatalogue()
{
string myQuery1 = "EXEC SelectLibraryCatalogue";
return new DataAccessLayer().ExecuteMyTable(myQuery1);
}
Sometimes my data grid loads a lots of data at once. 有时我的数据网格会一次加载很多数据。 I want to know how to achieve PAGING with this code.
我想知道如何使用此代码实现分页 。 Any code example would be really great.
任何代码示例都将非常棒。
Thanks in advance. 提前致谢。
Go through this detailed example 通过这个详细的例子
http://www.aspsnippets.com/Articles/Paging-in-ASPNet-GridView-Example.aspx http://www.aspsnippets.com/Articles/Paging-in-ASPNet-GridView-Example.aspx
You can do it by using the properties 您可以使用属性来完成
<asp:gridview id="GVView01"
allowpaging="true"
pagesize="15"
runat="server">
you can use pagesize="10"
(or 20 whatever size of page you want to display )property of gridview in designer page and provide allowpaging="true"
, in designer you can get both properties 您可以在设计器页面中使用
pagesize="10"
(或20个要显示的页面大小)的gridview属性,并提供allowpaging="true"
,在设计器中您可以同时获得这两个属性
<asp:GridView ID="GridView1" runat="server"
AutoGenerateColumns = "false" Font-Names = "Arial"
Font-Size = "11pt" AlternatingRowStyle-BackColor = "#C2D69B"
HeaderStyle-BackColor = "green" AllowPaging ="true"
OnPageIndexChanging = "OnPaging"
PageSize = "10" >
. 。 .
。 .
。
And now in order make the paging functionality work we will need to add the OnPageIndexChanging event of the GridView control 现在,为了使分页功能正常工作,我们将需要添加GridView控件的OnPageIndexChanging事件
protected void OnPaging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
GridView1.DataBind();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.