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.