Checkboxlist sample code
Now we are going to discuss about the Checkbox list Control so Checkboxlist allows user to select Multiple values , we will see how to retrieve the selected values from the Checkboxlist.
Here is the HTML Code
in Code behind , then place one label control to get the selectedvalue of checkboxlist
<asp:CheckBoxList ID="cblPlanets" runat="server" Width="109px">
<asp:ListItem Value="1">Mercury</asp:ListItem>
<asp:ListItem Value="2">Venus</asp:ListItem>
<asp:ListItem Value="3">Earth</asp:ListItem>
<asp:ListItem Value="4">Mars</asp:ListItem>
<asp:ListItem Value="5">Jupiter</asp:ListItem>
<asp:ListItem Value="6">Saturn</asp:ListItem>
<asp:ListItem Value="7">Uranus</asp:ListItem>
<asp:ListItem Value="8">Neptune</asp:ListItem>
</asp:CheckBoxList>
C# SOURCE
protected void btnSubmit_Click(object sender, EventArgs e)
{
lblText.Text = "You selected: ";
foreach (ListItem li in cblPlanets.Items)
{
if (li.Selected == true)
{
lblText.Text = lblText.Text += "~" + li.Text;
}
}
}
0 comments:
Post a Comment
Thanks for the Comments.