ASP 101 - Active Server Pages 101 dictionary.aspx
<%@ Page Language="VB" Explicit="true" %>
<%@ Import Namespace="System.Collections.Specialized" %>
<script runat="server">
	Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
		Dim objColorDict As StringDictionary
		Dim strColor As String
		Dim deColor As DictionaryEntry
		Dim strTemp As String
		' Create a StringDictionary object to hold our color information
		objColorDict = New StringDictionary()
		' Add some keys and items
		objColorDict.Add("black",   "#000000")
		objColorDict.Add("red",     "#FF0000")
		objColorDict.Add("yellow",  "#FFFF00")
		objColorDict.Add("green",   "#00FF00")
		objColorDict.Add("aqua",    "#00FFFF")
		objColorDict.Add("blue",    "#0000FF")
		objColorDict.Add("fuschia", "#FF00FF")
		objColorDict.Add("white",   "#FFFFFF")
		' Display all the keys and items
		strTemp = ""
		For Each strColor In objColorDict.Keys
			strTemp = strTemp & strColor & vbTab
			strTemp = strTemp & "<span style=""background-color: " & objColorDict.Item(strColor) & """>"
			strTemp = strTemp & objColorDict.Item(strColor)
			strTemp = strTemp & "</span>" & vbCrLf
		Next
		litAllEntries.Text = strTemp
		' Display the number of pairs in the dictionary
		litCount.Text = objColorDict.Count
		' Check if a key exists
		litBlueExists.Text = objColorDict.ContainsKey("blue")
		' Display a single item by accessing it via its key
		litBlueValue.Text = objColorDict.Item("blue")
		' Change the value of an item
		objColorDict.Item("blue") = "#000099"
		litBlueNewValue.Text = objColorDict.Item("blue")
		' Change the value of a key
		objColorDict.Add("dark blue", objColorDict.Item("blue"))
		objColorDict.Remove("blue")
		' Display all the keys and items again using different syntax
		strTemp = "<table border=""1"">" & vbCrLf
		strTemp = strTemp & "<tr><th>Key</th><th>Item</th></tr>" & vbCrLf
		For Each deColor in objColorDict
			strTemp = strTemp & "<tr>"
			strTemp = strTemp & "<td>" & deColor.Key & "</td>"
			strTemp = strTemp & "<td bgcolor=""" & deColor.Value & """>" & deColor.Value & "</td>"
			strTemp = strTemp & "</tr>" & vbCrLf
		Next
		strTemp = strTemp & "</table>" & vbCrLf
		litAllEntriesTable.Text = strTemp
		' Get rid of the dictionary
		objColorDict = Nothing
	End Sub
</script>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>ASP.NET Dictionary Sample from ASP 101</title>
</head>
<body>
<form id="myForm" runat="server">
	<p>All the keys and corresponding items in our dictionary object:</p>
<pre>
<strong>Key	Item</strong>
<asp:Literal id="litAllEntries" runat="server" />
</pre>
	<p>
	Number of key/item pairs in our dictionary:
	<asp:Literal id="litCount" runat="server" />
	</p>
	<p>
	Does a "blue" key exist:
	<asp:Literal id="litBlueExists" runat="server" />
	</p>
	<p>
	Value of the item corresponding to the "blue" key:
	<asp:Literal id="litBlueValue" runat="server" />
	</p>
	<p>
	Changing the value of the "blue" key's item.
	Its value is now:
	<asp:Literal id="litBlueNewValue" runat="server" />
	</p>
	<p>
	Changing the value of the "blue" key to
	"dark blue".
	</p>
	<p>All the keys and corresponding items in our dictionary object:</p>
	<asp:Literal id="litAllEntriesTable" runat="server" />
</form>
<hr />
<p>
Click <a href="http://www.asp101.com/samples/dictionary_aspx.asp">here</a>
to read about and download the source code.
</p>
</body>
</html>