RSS

Hashtable use for Checkboxlist

02 Jun

 

Client  Side / checkboxlist.aspx

 

 

<head runat=”server”>

<title></title>

</head>

<body>

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

<div>

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

</asp:CheckBoxList>

<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>

</div>

</form>

</body>

</html>

 

Severside/Codebehid/checkboxlisht.aspx.cs

 

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”;

CheckBoxList1.DataTextField=”Value”;

CheckBoxList1.DataBind();

}

}

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;”;

}

}

}

}

 

 

Advertisements
 
Leave a comment

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

 

Tags: , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: