Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to retrieve multiple selected value from asp:checkbox .net c#

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>  
like image 415
Jin Yong Avatar asked Jun 27 '11 07:06

Jin Yong


People also ask

Can checkbox select multiple values?

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.


1 Answers

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.

like image 126
Akram Shahda Avatar answered Oct 24 '22 06:10

Akram Shahda