Link to home
Start Free TrialLog in
Avatar of viola123
viola123

asked on

How to toggle a <hr> tag in code behind(.aspx.cs page)?

Hi All,
i have a gridView and have the following requirements:
<hr> is hidden when first loading the page;
when there is data in gridView---> display <hr>;
if there is no data in gridView---> hide <hr>;

i am using javascript to do it but i found <hr> is always hidden, can anyone point me to the right direction?

attached the code.


<hr id="hrExport" style=" display:none;" />

*********************************
string javaScript = string.Empty; 

        
        if (dt.Rows.Count > 0)
        {

            javaScript = @"<script type='text/javascript' >
                                function DisplayHr1() {
                                    var hr = document.getElementById('hrExport');
                                    hr.style.display = 'block'; 

                                }</script>";
            Page.ClientScript.RegisterStartupScript(this.GetType(), "DisplayHr1", javaScript); 


        }
        else
        {
            javaScript = @"<script type='text/javascript' >
                                function DisplayHr2() {
                                    var hr = document.getElementById('hrExport');
                                    hr.style.display = 'none'; 

                                }</script>";
            Page.ClientScript.RegisterStartupScript(this.GetType(), "DisplayHr2", javaScript); 

        }

Open in new window

SOLUTION
Avatar of Craig Wagner
Craig Wagner
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of viola123
viola123

ASKER

CraigWagner:
thanks a lot. i will try and let you know the result
hi,
i got error:
'System.Web.UI.WebControls.PlaceHolder' does not contain a definition for 'Text'

thanks
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
i figure it out based on Craig's suggestion.

thank you Craig!