How can I clear data in a GridView?

爱⌒轻易说出口 提交于 2019-12-24 05:24:27

问题


I have 3 GridViews in my page.

Using the SelectedIndexChanged event I put GridView2 and GridView3 data in GridView1 but when I restart my application GridView1 data is still persisted in browser.

I used a session variable to store the data. How can I clear GridView1


回答1:


You can try to clear the GridView1 itself every time you start the application:

protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                GridView1.DataSource = null;
                GridView1.DataBind();
            }

        }



回答2:


Before restarting your application, you've got to clear out your sessions if that's how you're storing the data. Clearing these session variables will clear your gridview.

Inside of your page load, you can do this.

if(!IsPostBack)
{
  Session["mySessionVariable"] = null;
  //...do this for each session variable you need to clear.
}



回答3:


put a new dataset or null value in your session.



来源:https://stackoverflow.com/questions/2252868/how-can-i-clear-data-in-a-gridview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!