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.

3

2 Answers 2

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);
Sign up to request clarification or add additional context in comments.

6 Comments

No its still not working. i think one cant alter css in 'GridView1_RowCommand' function. :(
Did you debug the code, when click on button goes to that line to set Visible to true?
yea did the debug. it executes the line but css 'Visibility' does not alter
set the AutoPostBack="true" for the button within grid. still doesn't work
As @Manish mentioned, should remove 'Visibility' from Html code and just adding Visible='false', then in your code only set the Visible=true. Don't need alter the Style
|
-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..

1 Comment

The question is how to remove Css on the serve side. stackoverflow.com/questions/4333570/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.