GridView分页
public void gridviewbind(){
DataTable CustmTable = GridGetSql("select * from EasAgeutInfo order by AgCode desc");
for (int i = CustmTable.Rows.Count; i < 14; i++)
{
DataRow TableRow = CustmTable.NewRow();
TableRow[0] = DBNull.Value;
CustmTable.Rows.Add(TableRow);
}
this.GridView2.DataSource = CustmTable;
this.GridView2.DataBind();
}
//载入页面时的方法
public DataTable GridGetSql(string SqlStr)
{
SqlCommand SqlCmd = new SqlCommand();
SqlCmd.Connection = new SqlConnection(strconn);
SqlCmd.CommandText = SqlStr;
SqlCmd.CommandType = CommandType.Text;
SqlDataAdapter SqlAd = new SqlDataAdapter(SqlCmd);
DataSet Rs = new DataSet();
Rs.Clear();
SqlAd.Fill(Rs);
return Rs.Tables[0];
}
//分页
protected void GridView2_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
//if(GridView2.PageIndex>=0 || GridView2.PageIndex<GridView2.PageCount)
//{
GridView2.PageIndex = e.NewPageIndex;
// GridView2.DataBind();
this.gridviewbind();
// }
}
当我单击第二页的时候就没有那么多页了,这是怎么回事. --------------------编程问答-------------------- if(GridView2.PageIndex> =0 ¦ ¦ GridView2.PageIndex <GridView2.PageCount)
这个不需要啊 --------------------编程问答-------------------- public DataTable GridGetSql(string SqlStr)
{
SqlCommand SqlCmd = new SqlCommand();
SqlConnection con =new SqlConnection(strconn); ---变化加了这个
SqlCmd.Connection = con; -----------变成这样
SqlCmd.CommandText = SqlStr;
SqlCmd.CommandType = CommandType.Text;
SqlDataAdapter SqlAd = new SqlDataAdapter(SqlCmd);
DataSet Rs = new DataSet();
Rs.Clear();
SqlAd.Fill(Rs);
con.close();------加上这个
return Rs.Tables[0];
}
补充:.NET技术 , ASP.NET