Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/303.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 如何在页面加载时保持选中复选框列表的第一项?_Asp.net - Fatal编程技术网

Asp.net 如何在页面加载时保持选中复选框列表的第一项?

Asp.net 如何在页面加载时保持选中复选框列表的第一项?,asp.net,Asp.net,我想知道,假设我有一个checkboxlist控件,比如说5个项目,我想在页面上加载第一个项目,也就是说,我想所有的checkboxlist项目在默认情况下都保持选中状态。我怎样才能完成这项任务。请指导我。 包含项目的我的复选框列表- {<asp:CheckBoxList ID="chktopics" runat="server" RepeatDirection="Horizontal" RepeatLayout="Flow" AutoPostBack="True"

我想知道,假设我有一个checkboxlist控件,比如说5个项目,我想在页面上加载第一个项目,也就是说,我想所有的checkboxlist项目在默认情况下都保持选中状态。我怎样才能完成这项任务。请指导我。 包含项目的我的复选框列表-

{<asp:CheckBoxList ID="chktopics" runat="server" RepeatDirection="Horizontal" 
        RepeatLayout="Flow" AutoPostBack="True" 
        onselectedindexchanged="chktopics_SelectedIndexChanged">
        <asp:ListItem>All</asp:ListItem>
        <asp:ListItem>Item1</asp:ListItem>
        <asp:ListItem>Item2</asp:ListItem>
        <asp:ListItem>Item 3</asp:ListItem>
        <asp:ListItem>Item 4</asp:ListItem>
        <asp:ListItem>Item 5</asp:ListItem>
    </asp:CheckBoxList>}
{
全部的
项目1
项目2
项目3
项目4
项目5
}
使用Selected=“true”


在您的ListItem中,有一个名为“Selected”的属性-将其设置为True如果有人试图取消选中它怎么办?可能吗?因为我的目标是使第一个元素保持选中状态,并且它应该保持只读,即它应该保持不变。
<asp:ListItem Selected="true">All</asp:ListItem>
<asp:CheckBoxList ID="chktopics" runat="server" RepeatDirection="Horizontal" 
    RepeatLayout="Flow" AutoPostBack="True" 
    onselectedindexchanged="chktopics_SelectedIndexChanged">
   <asp:ListItem Selected="true">All</asp:ListItem>
    <asp:ListItem>Item1</asp:ListItem>
    <asp:ListItem>Item2</asp:ListItem>
    <asp:ListItem>Item 3</asp:ListItem>
    <asp:ListItem>Item 4</asp:ListItem>
    <asp:ListItem>Item 5</asp:ListItem>
</asp:CheckBoxList>
chktopics.Items[0].Checked = ture;