Tag Archives: or How to give hashtable as a datasouce to checkboxlist

Hashtable use for Checkboxlist


Client  Side / checkboxlist.aspx



<head runat=”server”>




<form id=”form1″ runat=”server”>


<asp:CheckBoxList ID=”CheckBoxList1″ runat=”server”>


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

<br />

<br />

<br />

Text: <asp:Label ID=”Label1″ runat=”server” Text=”Label”></asp:Label>

<br />

Value:  <asp:Label ID=”Label2″ runat=”server” Text=”Label”></asp:Label>








using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Text;

using System.Collections;

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


protected void Page_Load(object sender, EventArgs e)


Label1.Text = string.Empty;

Label2.Text = string.Empty;

if (!IsPostBack)


Hashtable hs = new Hashtable();

hs.Add(“1”, “sajjad”);

hs.Add(“2”, “ahmed”);

hs.Add(“3”, “imtiaz”);

hs.Add(“4”, “ghazi”);

hs.Add(“5”, “sohail”);

hs.Add(“6”, “zahid”);

hs.Add(“7”, “irfan”);


CheckBoxList1.DataSource = hs;

CheckBoxList1.DataValueField = “Key”;





protected void Button1_Click(object sender, EventArgs e)




Label1.Text = string.Empty;

Label2.Text = string.Empty;

foreach (ListItem listitem in CheckBoxList1.Items)


if (listitem.Selected)


Label1.Text += listitem.Text + ” &nbsp; &nbsp; ,  &nbsp; &nbsp;”;

Label2.Text += listitem.Value + ” &nbsp; &nbsp; ,  &nbsp; &nbsp;”;







Leave a comment

Posted by on June 2, 2011 in ASP Dot Net C#


Tags: , ,