ASP.NET - Hide Gridview - Asked By Jahir on 10-Feb-12 01:01 AM

How to hide gridview1 and how to display gridview2,

hide gridview1 and set visible true for Gridview2
Somesh Yadav replied to Jahir on 10-Feb-12 01:18 AM

well it depends on what you are doing inside RunIt(); method

if you are updating a datasource binded to gridview then you can try this after RunIt();

GridView1.Visible = true;

Gridview1.DataBind();

or this(in case datasource is not binded to gridview already)

GridView1.Visible = true;

Gridview1.DataSource = dataSourceObject;         // replace dataSourceObject with your datasource Object

Gridview1.DataBind();

Web Star replied to Jahir on 10-Feb-12 01:42 AM
Hi maddy
I don't understand why you are asking such type of query which already you know that hide and show controls by setting visible property false or true on you page. that is simple thing and if you don't know than also you should check these on your page itself than only you aware more and more.
Sreekumar P replied to Jahir on 10-Feb-12 01:52 AM
Hi,

You can simple use the

GridView1.Visible = true; ///set false to hide.

This is for server side.

If from Javsscript (Client side)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
  <title></title>
 
 
  <script type="text/javascript">
     
    function hideGridView() {
      document.getElementById('<%=GridView1.ClientID %>').style.display = "none";
    }
    function showGridView() {
        document.getElementById('<%=GridView1.ClientID %>').style.display = "";
    }
  </script>
 
</head>
<body>
  <form id="form1" runat="server">
  <div>
    <asp:GridView ID="GridView1" runat="server">
    </asp:GridView>
      
    <a href="javascript:hideGridView()">Hide</a>
    <a href="javascript:showGridView()">Hide</a>
  </div>
  </form>
</body>
</html>