0

i have a div tag which has inline css whose visibility is hidden

 <div id="SecondGrid" runat="server" style="width:80%; margin-left:10%; visibility:hidden;">
//content
</div>

i have a button in gridview, on click of which i want to remove the visibility css of the above div

  protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "ShowCarModels")
        {
            CarBrandID = Convert.ToInt32(e.CommandArgument.ToString());
            BindGridView2(CarBrandID);
            SecondGrid.Style.Remove("visibility");

        }
    }

the div still appear to be hidden. can you please help me out.

Ritz Arlekar
  • 375
  • 1
  • 4
  • 20

2 Answers2

0

You should use Visible property. As you use your html control at server side you can use Visible property for show or hide control.

SecondGrid.Visible = true;

For above solution you need to change you html markup to follwing

<div id="SecondGrid" runat="server" visible="false" style="width:80%; margin-left:10%;">
//content
</div>

but if you want to continue with your markup you can also remove style using HtmlTextWriterStyle

SecondGrid.Style.Remove(HtmlTextWriterStyle.Visibility);
Manish Parakhiya
  • 3,732
  • 3
  • 22
  • 25
-1

dint found the reason as why none of the css style alteration were not working under 'GridView1_RowCommand' but found a work around for my solution. Just wanted to share.

have put the css in a class

  .SecondG 
        {
            visibility:hidden;
        }

assigned the class to div

  <div id="SecondGrid" runat="server" style="width:80%; margin-left:10%; padding:20px; border:1px solid #E6E6E6;" class="SecondG" >

created a javascript to remove the class from the div

  function ShowModel()
        {
               var d = document.getElementById("<%=SecondGrid.ClientID%>");
               d.className = "";

        }

called the above javascript function on button click in the grid.

 <asp:TemplateField ItemStyle-Width="5%" HeaderText="Models" HeaderStyle-CssClass="header-center">
                                        <ItemTemplate>
                                            <asp:Button ID="img_Save" runat="server" OnClientClick="ShowModel()" CommandArgument='<%# Eval("CarBrandID") %>' CommandName="ShowCarModels" Width="100%"  Text="Display Models"  />
                                        </ItemTemplate>
                                    </asp:TemplateField>

and its working. thanks a lot guys for the help..

Ritz Arlekar
  • 375
  • 1
  • 4
  • 20
  • The question is how to remove Css on the serve side. https://stackoverflow.com/questions/4333570/remove-css-class-in-code-behind – Tyler S. Loeper Sep 10 '18 at 19:18