简体   繁体   中英

Checkbox style attribute does not changing from code behind

I have added style="display:none" to CheckBox . On DropDownList1_SelectedIndexChanged event I have changed to display:block . But its not changing to block .

<div class="form-group">
    <asp:CheckBox ID="CheckBox1" runat="server" Text="Mark as close" style="display:none"/>
</div>

protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
     string s = DropDownList1.SelectedItem.Value;
     if (s == "3")
     {
         CheckBox1.Style.Add("display", "block");
         //  CheckBox1.Attributes.Add("Style", "display:block");
     }
     else
     {
         CheckBox1.Style.Add("display", "none");                    
     }        
}

You need to add the style like below:-

protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
    string s = DropDownList1.SelectedItem.Value;
    if (s == "3")
    {
       CheckBox1.Attributes["style"] = "display:block;";
    }
    else
    {
       CheckBox1.Attributes["style"] = "display:none;";
    }
}

尝试这个

CheckBox1.Style.Add(HtmlTextWriterStyle.Display, "block");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM