画面の各項目を読み取り専用で開きたいときありますよね。
今回はCheckBoxListを読み取り専用で開く方法です。
C#とVB両方でのやり方を紹介します。
やり方
aspxのコード(通常通り記載)
<asp:CheckBoxList ID="CheckBoxList1" runat="server">
<asp:ListItem Selected="True">項目1</asp:ListItem>
<asp:ListItem>項目2</asp:ListItem>
<asp:ListItem>項目3</asp:ListItem>
</asp:CheckBoxList>
aspx.csのコード
// CheckBoxList1を読み取り専用にする
foreach (ListItem item in CheckBoxList1.Items)
{
item.Enabled = false;
}
aspx.vbのコード
// CheckBoxList1を読み取り専用にする
For Each item As ListItem In CheckBoxList1.Items
item.Enabled = False
Next
結果は以下のようになり、読み取り専用で操作できなくなる。

コメント