[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 519
  • Last Modified:

clear datagridview with the header remain

how to clear only the items in datagridview with the header remain.
0
aarontham
Asked:
aarontham
1 Solution
 
kirihimeteCommented:
Weird request but if you want to hide all rows except the header, simply loop through each item (row) and set its visible property to false...

using System;
using System.Web.UI.WebControls;
 
public partial class _Default : System.Web.UI.Page
{
    /// <summary>
    /// Handles the Load event of the Page control.
    /// </summary>
    /// <param name="sender">The source of the event.</param>
    /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
    protected void Page_Load(object sender, EventArgs e)
    {
        DataSet1TableAdapters.CustomerTableAdapter tableAdapter = new DataSet1TableAdapters.CustomerTableAdapter();
 
        dgTest.DataSource = tableAdapter.GetData();
        dgTest.DataBind();
 
        foreach (DataGridItem item in dgTest.Items)
        {
            item.Visible = false;
        }
    }
}

Open in new window

0
 
Praveen VenuCommented:
sure
After the databind (bind to a datasource having atleast one column) add this code

 For i As Integer = 0 To GridView1.Rows.Count - 1
            GridView1.Rows(i).Visible = False
        Next
0
 
AllamzCommented:
Dear aarontham,

if you are working with Typed Dataset, the header will be available in all the cases so you can avoid the binding and save memory, if you are not working with typed datasets so you can follow praveenvenu method to hide the rows.

Best Regards,

Mohamed Allam
Senior Solution Developer
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
aaronthamAuthor Commented:
guys i want to clear all the data in datagridview with the header remain.
0
 
AllamzCommented:
aarontham,
are you working with typed or untyped datasets ?
0
 
kirihimeteCommented:
i'm dropping out - too ambiguous.
0
 
JediTobyCommented:
Aaron,

The easy way is to set the list being used as a datasource for the control to nothing. That retains the header and clears the client data beneath it.

Thus:


 Me.Tbl_SampleBindingSource.DataSource = Nothing
me.Tbl_Sample.DataSourc=Me.Tbl_SampleBindingSource

Open in new window

0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now