How can I clear data in a GridView?
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.
精彩评论