简体   繁体   中英

how do I “unload” a GridView on my ASP .NET web page?

when the page starts, I cannot SEE the GridView even though it's set to "visible."

I only see it after data has been loaded into it.

After data has been loaded into it, how can I "unload" it? Meaning, how can I make it disappear the same way it was BEFORE data was bound to it?

Not sure if I get your question but something like this would empty the grid on server side

gridView1.DataSource = null;
gridView1.DataBind();

On page load do this:

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

Oh and set the show header when empty property of the grid view in your aspx:

ShowHeaderWhenEmpty="true"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM