简体   繁体   English

复选框样式属性不会从后面的代码更改

[英]Checkbox style attribute does not changing from code behind

I have added style="display:none" to CheckBox . 我已经将style="display:none"CheckBox On DropDownList1_SelectedIndexChanged event I have changed to display:block . DropDownList1_SelectedIndexChanged事件上,我已更改为display:block But its not changing to block . 但是它并没有改变以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");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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