本文介绍了如何在动态gridview中创建分页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用C#,在这里我附上我的动态网格视图的部分代码,它的工作正常。我需要在动态网格视图上设置分页如何调用OnPageIndexChanging
I am using C# ,here i attach my partial code for dynamic grid view its working fine . I need to set paging on the dynamic grid view how can i call the OnPageIndexChanging
GridView gv = new GridView();
gv.AllowPaging = false;
gv.AlternatingRowStyle.BackColor = System.Drawing.Color.WhiteSmoke;
gv.GridLines = GridLines.Horizontal;
gv.CellPadding = 2;
gv.CellSpacing = 5;
gv.HeaderStyle.BackColor=System.Drawing.Color.Black;
gv.HeaderStyle.ForeColor = System.Drawing.Color.White;
gv.AutoGenerateColumns = false;
BoundField nameColumn = new BoundField();
nameColumn.DataField = "fld_id";
nameColumn.HeaderText = "First Name";
gv.Columns.Add(nameColumn);
nameColumn = new BoundField();
nameColumn.DataField = "fld_name";
nameColumn.HeaderText = "Last Name";
gv.Columns.Add(nameColumn);
nameColumn = new BoundField();
nameColumn.DataField = "fld_state";
nameColumn.HeaderText = "Age";
gv.Columns.Add(nameColumn);
gv.DataSource = ds;
gv.DataBind();
plangrid.Controls.Add(gv);
推荐答案
gv.AllowPaging = true;
gv.PageSize =10;
gv.PageIndexChanged+= new EventHandler(grid1_PageIndexChanged);
protected void grid1_PageIndexChanged(object sender, GridViewPageEventArgs e)
{
gv.PageIndex = e.NewPageIndex;
gv.Databind();
}
这篇关于如何在动态gridview中创建分页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!