This tutorial will show you how to store data with Hashtable using ASP.NET 2.0 and VB.NET.
At first, you need to import the namespace from System.Collections.The System.Collections namespace contains classe Hashtable which represents a collection of key/value pairs that are organized based on the hash code of the key.
| Imports System.Collections |
Server Intellect offers Windows Hosting Dedicated Servers at affordable prices. I'm very pleased!
In order to run the example, we will use the btn_get_Click to trigger the task. The code as following:
| Protected Sub btn_get_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btn_get.Click Dim key As Integer End Sub Dim name As String = String.Empty Dim str As String = String.Empty Dim hashtable As Hashtable = New Hashtable() key = 1 name = "Jake" Hashtable.Add(key, name) key = 2 name = "peter" Hashtable.Add(key, name) key = 3 name = "lily" Hashtable.Add(key, name) For Each de As DictionaryEntry In hashtable str = str + "key=" + CType(de.Key, String) + " " + " value=" + de.Value.ToString() + "<br>" Next deMe.Label1.Text = str |
Try Server Intellect for Windows Server Hosting. Quality and Quantity!
The front end StoreDataWithHashtableVB.aspx page looks something like this:| <div align="left" style="text-align: center"> <table> <tr> </table><td colspan="2" style="width: 402px"> </tr><asp:Label ID="Label1" runat="server"></asp:Label> </td> <tr> <td colspan="2" style="height: 26px; width: 402px;"> </tr><asp:Button ID="btn_get" runat="server" Text="Get data from hashtable" OnClick="btn_get_Click"/></td> </div> |
Server Intellect assists companies of all sizes with their hosting needs by offering fully configured server solutions coupled with proactive server management services. Server Intellect specializes in providing complete internet-ready server solutions backed by their expert 24/365 proactive support team.
The flow for the code behind page is as follows| Imports System.Collections Inherits System.Web.UI.Page End Class Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load ' This tutorial is provided in part by Server Intellect Web Hosting Solutions http://www.serverintellect.com End Sub' Visit http://www.AspNetTutorials.com for more ASP.NET Tutorials Protected Sub btn_get_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btn_get.Click Dim key As Integer End SubDim name As String = String.Empty Dim str As String = String.Empty Dim hashtable As Hashtable = New Hashtable() key = 1 name = "Jake" Hashtable.Add(key, name) key = 2 name = "peter" Hashtable.Add(key, name) key = 3 name = "lily" Hashtable.Add(key, name) For Each de As DictionaryEntry In hashtable str = str + "key=" + CType(de.Key, String) + " " + " value=" + de.Value.ToString() + "<br>" Next deMe.Label1.Text = str |
No comments:
Post a Comment