Click here to hide categories Click here to show left categories

User: Home          welcome : Guest          Log In / Register here     




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.

Share this article   |    Print    |    Article read by 1866 times
Author:
Rohit kakria
I am software developer, moderator of xpode.com
Related Articles:
Related Interview Questions: