簡體   English   中英

復選框樣式屬性不會從后面的代碼更改

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

我已經將style="display:none"CheckBox DropDownList1_SelectedIndexChanged事件上,我已更改為display: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");                    
     }        
}

您需要添加如下樣式 :-

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