Does anyone know how can I retrieved the multiple selected value from asp:checkbox .net c#?
Example: I'm new in .net c#, I have the following code, but I have no idea how can I retrieved the multiple selected value from .net c#
<tr>
<th class="graytext r">Add Test:</th>
<td>
<asp:CheckBoxList ID="Test" runat="server" DataSourceID="dsTest" CssClass=""
DataValueField="employeeid" DataTextField="fullname"
AppendDataBoundItems="false" >
<asp:ListItem></asp:ListItem>
</asp:CheckBoxList>
<asp:SqlDataSource ID="dsTest" runat="server"
ConnectionString="<%$ ConnectionStrings:SmartStaffConnectionString %>"
SelectCommand="app_dsTest_select" SelectCommandType="StoredProcedure">
</asp:SqlDataSource>
</td>
</tr>
Remember that checkbox is different from the radio button and dropdown list because it allows multiple selections at once. In contrast, the radio button and dropdown allow us to choose only one from the given options.
Use the following:
for (int i=0; i<checkboxlist1.Items.Count; i++)
{
if (checkboxlist1.Items[i].Selected)
{
Message.Text += checkboxlist1.Items[i].Text + "<br />";
}
}
Refer to CheckBoxList Class.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With