Click here to Skip to main content
15,798,825 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how can i select the single check while multiple check box are present...
Posted

1 solution

Default.aspx
XML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:CheckBoxList ID="CheckBoxList1" runat="server">
            <asp:ListItem>Swaminarayan-BAPS</asp:ListItem>
            <asp:ListItem>Microsoft</asp:ListItem>
            <asp:ListItem>Apple</asp:ListItem>
            <asp:ListItem>Oracle</asp:ListItem>
            <asp:ListItem>IBM</asp:ListItem>
        </asp:CheckBoxList>
    </div>
    <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
    <p>
        <asp:TextBox ID="TextBox1" runat="server" Height="165px" TextMode="MultiLine"
            Width="242px"></asp:TextBox>
    </p>
    </form>
</body>
</html>


==========================================================================
Default.aspx.cs
C#
public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        TextBox1.Text ="";
        foreach(ListItem lst in CheckBoxList1.Items)
        {
            if(lst.Selected==true)
            TextBox1.Text += lst.Text + "\n";
        }
    }
}


Now simply make change or add another contidtion with the if() & modify.It's so easy now
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900