2

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

3 Answers 3

6

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

        }
0

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

put a new dataset or null value in your session.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.