Я хочу знати, що, мабуть, у мене є прапорецьконтроль з сказати 5 пунктів, і я хочу, щоб на сторінці завантажувався самий перший елемент, тобто я хочу, щоб елемент весь список прапорців залишався обраним за замовчуванням. Як я можу виконати це завдання? Будь ласка, допоможіть мені. Мій прапорець із елементами-
{<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>}
Відповіді:
2 для відповіді № 1Використовуйте "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>
У коді позаду ви можете це зробити в event_page_load
chktopics.Items[0].Checked = ture;