You must Sign In to post a response.
  • Category: ASP.NET

    How to hide grid view in using c#

    Am new to we created a grid view to display data in the webpage. intially the grid view data need to be hide. after clicking the search button it should get display according to the search criteria.
  • #763570
    Hi Vivek,

    What's your problem on here, have you tried Visible property of gridview by setting it true or false for visible or invisible based on your condition.



    Try like above if you still having issue, I request you to please let us know, so that we can help you better.

    Hope this will helpful to you..

    Give respect to your work, Instead of trying to impress your boss.

    Blog :

  • #763592
    Here are some of the ways to hide gridview
    1. You can set 'style.display' property to 'none' to hide gridview
    2. Make .visible property of the gridview to empty, see below
    if (this.GridView1.Rows.Count == 0)
    this.GridView1.Visible = false;
    3. you can directly code in ASPX too
    <asp:Gridview id="gridview" ......
    Visible='<%# ((ICollection)gridview.DataSource).Count == 0 ? false : true %>'>
    4. add empty data source to gridview

    Editor, DotNetSpider MVM
    Microsoft MVP 2014 [ASP.NET/IIS]

  • #763659
    try this.
    this.GridView1.Visible = false;

  • #763679
    Hi Vivek,
    If you just want to show the header and not the data for the first time, then you can bind your grid with the null dataset and add the headers only.
    Hope it will be helpful to you.

    Pawan Awasthi(DNS MVM)
    +91 8123489140 (whatsApp), +60 14365 1476(Malaysia)

  • #763740
    First of all, one needs to create a background for creating rows and item data bound events that permit you to introduce JavaScript, CSS, and HTML. They help in developing the Grid view. While creating the grid view, it is set as hidden by default. Also, there is a plus (+), and minus (-) option visible on top. If you click on minus, your grid will be hidden and if you click on plus (+), the grid will be visible.
    Also, if you are using ASP.NET with C# for grid, then don't bind your grid view. So that, it remains hidden by all.

  • #763864
    When someone search something if result datatable has rows count more than 0 then bind and set the grid visible true otherwise false.
    If you are unable to do something properly for the first time, call it Version 1.0!

    Thanks & Regards,

  • #764098

    1) If you are binding your grid view with the help of SqlDataSource then
    a)At page load assign SqlDataSourceID.SelectCommand = "";
    b)On search button click assign SqlDataSourceID.SelectCommand = "desired select statement";
    2) You can also try this:
    GridViewID.DataSource = null;

    Hope this will help you.

    Shashikant Gurav[Programmer II]

  • #764101
    Do not bind the data in the page load. So the grid will be hidden.

    In the search box button click you can get and assign the data source, then bind the data .

    By Nathan
    Direction is important than speed

  • Sign In to post your comments