GridView分页的问题?
if (!IsPostBack)
{
string sql = "select *,datediff(hh,getdate(),yqwc_time) as sy from ask_info where request_man= ' " + Session[ "user_name "].ToString() + " ' order by ask_from_time desc ";
ask_list(sql, GridView1);
}
public void ask_list(string sql, GridView GridView1)
{
SqlConnection con = DB.CreateConn();
SqlDataAdapter sda = new SqlDataAdapter(sql, con);
DataSet myds = new DataSet();
con.Open();
sda.Fill(myds, "ask_list ");
GridView1.DataSource = myds.Tables[0];
GridView1.DataKeyNames = new string[] { "id " };//主键
GridView1.DataBind();
sda.Dispose();
con.Close();
con.Dispose();
}
我在GridView属性里设置了AllowPaging= "True "
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
}
我为什么我点击GridView控件上的自动生成的页数不换页呢?
而且点一个页数时要点两下才不能点(没有连接了)
请指教!
------解决方案--------------------GridView1.PageIndex = e.NewPageIndex;
重新绑定
ask_list(sql, GridView1);
------解决方案--------------------protected void BindData()
{
string sql = "select *,datediff(hh,getdate(),yqwc_time) as sy from ask_info where request_man= ' " + Session[ "user_name "].ToString() + " ' order by ask_from_time desc ";
SqlConnection con = DB.CreateConn();
SqlDataAdapter sda = new SqlDataAdapter(sql, con);
DataSet myds = new DataSet();
con.Open();
sda.Fill(myds, "ask_list ");
GridView1.DataSource = myds.Tables[0];
GridView1.DataKeyNames = new string[] { "id " };//主键
GridView1.DataBind();
sda.Dispose();
con.Close();
con.Dispose();
}
...
if (!IsPostBack)
{
BindData();
}
...
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;