Click here to Skip to main content
16,017,167 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How to get ID of CheckBox list items when I check its item , I use c# in winddow application Please help
Posted
Updated 12-May-14 2:10am
v2
Comments
[no name] 12-May-14 7:38am    
Help with what? Help to stop screaming at us?
Sayan Bera 12-May-14 8:09am    
What is CHECKBOXLIST in C# Windows Application?
Are you using Few checkboxes or CheckedListBox?
Member 10285877 12-May-14 8:12am    
i am use CheckedListBox?
Sayan Bera 12-May-14 8:29am    
Are you asking what to use or saying what you are using?
 
Anyways -> Handle the ItemChecked event for the control if you are using CheckedListBox.

private void OnItemChecked(object sender, ItemCheckEventArgs e)<br>
{
//foreach (string obj in checkedListBox1.CheckedItems)
//{
// MessageBox.Show(Obj);
//}
MessageBox.Show("Name: "+checkedListBox1.SelectedItem.ToString()+" Index: "+checkedListBox1.SelectedIndex.ToString());
}

1 solution

See this example :

XML
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default3.aspx.cs" Inherits="Default3" %>

<!DOCTYPE html>

<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" AutoPostBack="True" Height="31px" OnSelectedIndexChanged="CheckBoxList1_SelectedIndexChanged" Width="140px">
 <asp:ListItem>Adrotator</asp:ListItem>
 <asp:ListItem>BulletedList</asp:ListItem>
 <asp:ListItem>Button</asp:ListItem>
 <asp:ListItem>Calendar</asp:ListItem>
 <asp:ListItem>DropDownList</asp:ListItem>
 </asp:CheckBoxList>
 <br />
 </div>
 <asp:Label ID="Label1" runat="server"></asp:Label>
 </form>
 </body>
 </html>
Codebehind
using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Web;
 using System.Web.UI;
 using System.Web.UI.WebControls;

public partial class Default3 : System.Web.UI.Page


{
  protected void Page_Load(object sender, EventArgs e)



{

}
  protected void CheckBoxList1_SelectedIndexChanged(object sender, EventArgs e)



{
  foreach (ListItem item in CheckBoxList1 .Items)



{
  if (item.Selected)



{

Label1.Text += item.Text;

}

}

}

}
 
Share this answer
 
Comments
Member 10285877 12-May-14 8:10am    
sir in window application

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