<asp:DropDownCheckBoxes ID="ddchkCountry" runat="server" AddJQueryReference="True" UseButtons="True" UseSelectAllNode="True"> <Style SelectBoxWidth="200" DropDownBoxBoxWidth="200" DropDownBoxBoxHeight="130" /> <Texts SelectBoxCaption="Select Country" /></asp:DropDownCheckBoxes> <asp:Label ID="lblCountryID" runat="server"></asp:Label><br /> <asp:Label ID="lblCountryName" runat="server"></asp:Label> <asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClick="btnSubmit_Click"/>
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data; using System.Data.SqlClient; using System.Configuration; namespace DropDownList19_12 { public partial class Register : System.Web.UI.Page { SqlConnection conn = new SqlConnection("Data Source=DLITTLES-PC;Database=MultiCheck;Integrated Security=True"); protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { BindData(); } } protected void BindData() { DataSet ds = new DataSet(); string cmdstr = "select CountryID,Country from Country"; SqlDataAdapter adp = new SqlDataAdapter(cmdstr, conn); adp.Fill(ds); if (ds.Tables[0].Rows.Count > 0) { ddchkCountry.DataSource = ds.Tables[0]; ddchkCountry.DataTextField = "Country"; ddchkCountry.DataValueField = "CountryID"; ddchkCountry.DataBind(); } } protected void btnSubmit_Click(object sender, EventArgs e) { List<string> CountryID_list = new List<string>(); List<string> CountryName_list = new List<string>(); foreach (System.Web.UI.WebControls.ListItem item in ddchkCountry.Items) { if (item.Selected) { CountryID_list.Add(item.Value); CountryName_list.Add(item.Text); } lblCountryID.Text = "Country ID: " + String.Join(",", CountryID_list.ToArray()); lblCountryName.Text = "Country Name: " + String.Join(",", CountryName_list.ToArray()); } } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)