开发者

How can I clear data in a GridView?

开发者 https://www.devze.com 2022-12-20 04:15 出处:网络
I have 3 GridViews in my page. Using the SelectedIndexChanged event I put GridView2 and GridView3 data in GridView1

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 persiste开发者_Python百科d in browser.

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


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();
            }

        }


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.
}


put a new dataset or null value in your session.

0

精彩评论

暂无评论...
验证码 换一张
取 消