| HTML Tutorials |
|
|
| XML Tutorials |
|
|
| Browser Scripting |
|
|
| Server Scripting |
|
|
| .NET (dotnet) |
|
|
| Multimedia |
|
|
| Web Building |
|
|
| Java Tutorials |
|
|
| Programming Langauges |
|
|
| Soft Skills |
|
|
|
| ASP.NET - The Hashtable Object |
|
The Hashtable object contains items in the form of key/value pairs.
|
|
The SortedList Object
|
|
The Hashtable object contains items in the form of key/value pairs and the keys are used as indexes, and very quick searches can be made for values by searching through their keys.
With the Add() method,items are added to the Hashtable.
The code below creates a Hashtable named mycountries and four elements are added:
|
<script runat="server">
Sub Page_Load
if Not Page.IsPostBack then
dim mycountries=New Hashtable
mycountries.Add("N","Norway")
mycountries.Add("S","Sweden")
mycountries.Add("F","France")
mycountries.Add("I","Italy")
end if
end sub
</script>
|
|
|
Data Binding
|
|
A Hashtable object may automatically generate the values and text
to the following controls:
- asp:RadioButtonList
- asp:CheckBoxList
- asp:DropDownList
- asp:Listbox
First create a RadioButtonList control (without any asp:ListItem elements) in
an .aspx page to bind data to a RadioButtonList control:
|
<html>
<body>
<form runat="server">
<asp:RadioButtonList id="rb" runat="server"
AutoPostBack="True" />
</form>
</body>
</html>
|
|
|
Then add the following script that builds the list:
|
<script runat="server">
sub Page_Load
if Not Page.IsPostBack then
dim mycountries=New Hashtable
mycountries.Add("N","Norway")
mycountries.Add("S","Sweden")
mycountries.Add("F","France")
mycountries.Add("I","Italy")
rb.DataSource=mycountries
rb.DataValueField="Key"
rb.DataTextField="Value"
rb.DataBind()
end if
end sub
</script>
<html>
<body>
<form runat="server">
<asp:RadioButtonList id="rb" runat="server"
AutoPostBack="True" />
</form>
</body>
</html>
|
|
|
Then in the RadioButtonList control,we add a sub routine to be executed when the user clicks on an item.A text will appear in a label,when a radio button is clicked:
|
<script runat="server">
sub Page_Load
if Not Page.IsPostBack then
dim mycountries=New Hashtable
mycountries.Add("N","Norway")
mycountries.Add("S","Sweden")
mycountries.Add("F","France")
mycountries.Add("I","Italy")
rb.DataSource=mycountries
rb.DataValueField="Key"
rb.DataTextField="Value"
rb.DataBind()
end if
end sub
sub displayMessage(s as Object,e As EventArgs)
lbl1.text="Your favorite country is: " & rb.SelectedItem.Text
end sub
</script>
<html>
<body>
<form runat="server">
<asp:RadioButtonList id="rb" runat="server"
AutoPostBack="True" onSelectedIndexChanged="displayMessage" />
<p><asp:label id="lbl1" runat="server" /></p>
</form>
</body>
</html>
|
|
|
Note: You cannot choose the sort order of items added to the Hashtable.
Use the SortedList object,to sort items alphabetically or numerically.
|
Share And Enjoy:These icons link to social bookmarking sites where readers can share and discover new web pages.
Keywords:
ASP.NET using The Hashtable Object,
vb net hashtable,
asp net hashtable,
vb net using,
asp net object,
vb net object,
visual basic object,
visual basic using,
asp net using,
c# hashtable,
java hashtable,
jsp hashtable,
c# using,
hashmap hashtable,
hashtable api,
hashtable array,
sort hashtable,
hashtable collection,
vb hashtable,
java object,
hashtable serializable,
arraylist object,
hashtable example,
c# object,
arraylist hashtable,
hashtable string,
hashtable enumeration,
hashtable iterator,
value object,
static hashtable,
hashtable value,
object string,
hashtable xml,
using msdn
|
|
| HTML Quizes |
|
|
| XML Quizes |
|
|
| Browser Scripting Quizes |
|
|
| Server Scripting Quizes |
|
|
| .NET (dotnet) Quizes |
|
|
| Multimedia Quizes |
|
|
| Web Building Quizes |
|
|
| Java Quizes |
|
|
| Programming Langauges Quizes |
|
|
| Soft Skills Quizes |
|
|
|