大家好,当我在界面点击【下一页】时,怎样才能记住bool sh的值。同时在翻页事件中我进入不了if(sh==true),怎么可以进入?谢谢,各位大虾!
public partial class admin_NewsCheck : System.Web.UI.Page
{
public bool sh;
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
bind();
}
}
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
if (sh == true)
{
string sql11;
sql11 = "select t.DictName as CtType,h.ID, h.Title,h.AddDate,h.AddUser,h.IsNews_auditing from Hs_Dict t, HS_News h WHERE t.ID=h.CtType and (t.ID in (11,12,13,21,22,23,24,41,42,43,51,52,53,54)) and IsNews_auditing=1 ";
GridView1.DataSource = access.GreatDs(sql11);
GridView1.DataBind();
}
else
{
bind();
}
}
------解决方案--------------------------------------------------------
大家好,当我在界面点击【下一页】时,怎样才能记住bool sh的值。同时在翻页事件中我进入不了if(sh==true),怎么可以进入?
////////
aspx中的变量是不会保留状态的,当执行protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)的时候页面会重新载入,这个时候你的bool sh重新进行了定义,回到了sh=false的这个定义的时候的值了
如果你想保留这个值的话可以用ViewSate来进行保留。
protected void Page_Load(object sender, EventArgs e)
{
ViewState[ "sh "]=false;
if (!this.IsPostBack)
{
bind();
}
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
sh= (bool) ViewState[ "sh "];
if (sh == true)
------解决方案--------------------------------------------------------
public bool sh;
改成 public static bool sh;