user3326972
user3326972

Reputation: 1

How to make a hidden gridview

I want to keep my grid view hidden until and unless search button is been clicked

   <td class="style2">
                <asp:TextBox ID="txtbkcgry" runat="server" Width="233px"></asp:TextBox>
            </td>
            <td class="style3">
                Auther</td>
            <td class="style4">
                <asp:TextBox ID="txtathr" runat="server" Width="235px"></asp:TextBox>
            </td>
            <td rowspan="2">
                <asp:Button ID="Button1" runat="server" Text="Search" Width="143px" 
                    onclick="Button1_Click" />
            </td>
        </tr>
        <tr>
            <td class="style1">
                Book Name</td>
            <td class="style2">
                <asp:TextBox ID="txtbknm" runat="server" Width="232px"></asp:TextBox>
            </td>
            <td class="style3">
                Price</td>
            <td class="style4">
                <asp:TextBox ID="txtprs" runat="server" Width="233px"></asp:TextBox>

Please guide me with the query.

Upvotes: 0

Views: 102

Answers (3)

Murali Murugesan
Murali Murugesan

Reputation: 22619

You can simply do this very well in client side.

Initially you can set the gridview style to display none in server side

protected void Page_Load(object sender, EventArgs e)
{
    gridview1.Style.Add(HtmlTextWriterStyle.Display,"none");
    //or//gridview1.Attributes.Add("style","display:none");
}

In a client side when a button is clicked

 <asp:Button Text="Search" ID="txtSearch" runat="server"
  OnClientClick="return showGridView()" />

In a javascript

function showGridView() 
{  
  document.getElementByID("<%=gridView1.ClientID %>").style.display="block";
  return false;
}

Note:

ASP.Net gridview will be rendered as HTML <table style="display:none" id="gridView1"> Please see the viewsource of a page and ensure that it added the display:none

Upvotes: 2

invernomuto
invernomuto

Reputation: 10211

specify a css class to your gridview where you say display: none, then change the css class of gridview to display block, or remove class to gridview

Upvotes: 0

Nagaraj S
Nagaraj S

Reputation: 13474

This one

<asp:GridView ID="gridview1" runat="server" visible="false" ></asp:GridView>

In button event make it visible

protected void Button1_Click(object sender, EventArgs e)
        {
             gridview1.visible = true;
        }

Upvotes: 2

Related Questions