You create a new object of type
System.Collections.HashTable called myHash.
Then, you add keys to the hash table by using the add method and passing in the
name and value of each key.You can then retrieve the values of each key by using
myHash("KeyName").The value is returned as type of object, so if you need to convert it
into a string, as in the following example, you simply call the ToString() method.
Otherwise, you'll need to cast it to the type of object that you need.
The ASPX page is as follows:
<%@Import namespace="System.Collections"%>
<%@Import namespace="System.Drawing"%>
<HTML>
<body>
<form method="post" runat="server">
<asp:Label ID="MyLabel" Runat="server">Sample Text</asp:Label><br>
</form>
</body>
</HTML>
In <script runat="server" /> block or codebehind:
Sub Page_Load(sender As Object, e As EventArgs)
Dim myHash As New Hashtable()
myHash.Add("Red", "#FF0000")
myHash.Add("Green", "#00FF00")
myHash.Add("Blue", "#0000FF")
MyLabel.BackColor=ColorTranslator.FromHtml(myHash("Blue").ToString())
MyLabel.ForeColor=ColorTranslator.FromHtml(myHash("Red").ToString())
End Sub
No comments:
Post a Comment