HTML
<asp:Panel ID="Panel1" runat="server">
<asp:CheckBox ID="CheckBox1" runat="server" Text = "Mango" />
<asp:CheckBox ID="CheckBox2" runat="server" Text = "Apple" />
<asp:CheckBox ID="CheckBox3" runat="server" Text = "Orange" />
<asp:CheckBox ID="CheckBox4" runat="server" Text = "Banana" />
</asp:Panel>
<br />
<asp:Label ID="lblFruits" runat="server" Text=""></asp:Label>
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
C#
protected void Button1_Click(object sender, EventArgs e)
{
string fruits = " ";
foreach (Control c in Panel1.Controls)
{
if (c is CheckBox && (c as CheckBox).Checked)
{
fruits += (c as CheckBox).Text + ",";
}
}
lblFruits.Text = fruits.Substring(0, fruits.Length - 1);
}
VB
Protected Sub Button1_Click(sender As Object, e As EventArgs)
Dim fruits As String = " "
For Each c As Control In Panel1.Controls
If TypeOf c Is CheckBox AndAlso TryCast(c, CheckBox).Checked Then
fruits += TryCast(c, CheckBox).Text + ","
End If
Next
lblFruits.Text = fruits.Substring(0, fruits.Length - 1)
End Sub