gridview中的分页怎么写? 谁能给一个分页的完整的代码?还有那个PageIndexChanging事件中写什么?万分感谢!
gridview中的分页怎么写?
谁能给一个分页的完整的代码?还有那个PageIndexChanging事件中写什么?万分感谢!
------解决方案--------------------去网上搜 gridview72般绝技吧
------解决方案--------------------protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
this.GridView1.PageIndex = e.NewPageIndex;
BindData();
}
public void BindData()
{
SqlConnection con = db.con();
con.Open();
SqlDataAdapter das = new SqlDataAdapter(sql, con);
DataSet ds = new DataSet();
das.Fill(ds, (AspNetPager1.CurrentPageIndex - 1) * AspNetPager1.PageSize, AspNetPager1.PageSize, "temp");
con.Close();
this.DataList1.DataSource = ds.Tables["temp"].DefaultView;
this.DataList1.DataBind();
}
AspNetPager1控件自己随便找下,网上一大把
------解决方案--------------------前台
<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" AllowPaging="True" OnPageIndexChanging="GridView1_PageIndexChanging" PageSize="50" GridLines="None" >
隐藏页面
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView2.PageIndex = e.NewPageIndex;
具体的sql语句
}
------解决方案--------------------gridview 不是自带分页事件么?
前台将允许分页属性 设置为true,再设置page_size
C# code
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
this.GridView1.PageIndex = e.NewPageIndex;
[color=#FF0000]BindData(); [/color]--- 这是你自己的绑定gridview的方法
}