Xpode.com        Click here to Print this article.

Hash Table in Asp.Net 2.0

Hash table is an object where we can store the value and its key. (key/value pair) We can add the values and keys with Add Property

HashTable HshObj =  New HashTable();
HshObj.Add("C","Carrot")
HshObj.Add("P","Potato")
HshObj.Add("A","Apple")

We Will take the Example of RadioButtonList

rb.DataSource=HshObj;
rb.DataValueField="Key"
rb.DataTextField="Value"
rb.DataBind();

There are many controls like given below who needs to assign the Text and Value Property Sepertatly, But with these controls ArrayList automatically generates the text and values to the following controls:

* asp:RadioButtonList
* asp:CheckBoxList
* asp:DropDownList
* asp:Listbox

To Bind with these controls you need to just need to change the below code:

RdBtn.DataSource=HshObj;
RdBtn.DataValueField="Key"
RdBtn.DataTextField="Value"
RdBtn.DataBind();

Change the Id of the control with RdBtn.



http://


Contributed by:
Rohit kakria
I am software developer, moderator of xpode.com

Resourse address on xpode.com
http://www.xpode.com/Print.aspx?Articleid=74

Click here to go on website