Click here to Skip to main content
15,881,812 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
how to display the selected values of checkboxlist in an alert in javascript
eg:
C#
<asp:CheckBoxList ID="chklist" runat="server" >
<asp:ListItem Text="Apple" Value="Apple">
<asp:ListItem Text="Banana" Value="Banana">
<asp:ListItem Text="Orange" Value="Orange">

if we select any 3 items the output should be as below
output: Apple , Banana and Orange
Posted
Updated 19-Aug-14 22:41pm
v2
Comments
Ashi0891 19-Aug-14 7:34am    
what have you tried yourself? Did you google it? even if you just copy paste your title in google search engine you will get exact answers and similar posts on codeproject.com itself. Please try to solve your problem on your own before pasting it here!!

1 solution

aspx page code:

XML
<asp:CheckBoxList ID="CheckBoxList1" runat="server">
  <asp:ListItem Text="Apple" Value="Apple"></asp:ListItem>
  <asp:ListItem Text="Banana" Value="Banana"></asp:ListItem>
  <asp:ListItem Text="Orange" Value="Orange"></asp:ListItem>
</asp:CheckBoxList>

<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />


code behind(aspx.cs):

C#
protected void Button1_Click(object sender, EventArgs e)
    {
        string abc = "";
        foreach (ListItem item in CheckBoxList1.Items)
        {
            if (item.Selected)
            {
                abc += item.Value + ',';
            }
        }
        string test = "you have selected " + abc;
        Label labelshow = new Label();
        labelshow.Text = "<script language='javascript'>" + Environment.NewLine + "window.alert('" + test + "')</script>";
        Page.Controls.Add(labelshow);
    }


is this what you were looking for? Hope it Helps!
 
Share this answer
 
Comments
Ashi0891 19-Aug-14 9:40am    
Please mark it as answer if you got the required result :)
Thanks7872 19-Aug-14 10:11am    
Don't post multiple solutions to single question. Update the old one only.
Ashi0891 19-Aug-14 12:43pm    
M sorry. I'm new here. So Dnt really know about the rules. I'll make sure of this in future.

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