Bind Hashtable to DropDownList (VB.net) : DropDownList « Data Binding « ASP.Net






Bind Hashtable to DropDownList (VB.net)

<%@ Page Language="VB" %>
<script runat="server">
    Dim ColorList(6) as String
    Dim FontList as new ArrayList()
    Dim QuoteList as new Hashtable()
    
    Sub Page_Load
      ColorList(0) = "Red"
      ColorList(1) = "Orange"
      ColorList(2) = "Yellow"
      ColorList(3) = "Green"
      ColorList(4) = "Blue"
      ColorList(5) = "Indigo"
      ColorList(6) = "Violet"
    
      FontList.Add("Times New Roman")
      FontList.Add("Arial")
      FontList.Add("Verdana")
      FontList.Add("Comic Sans MS")
      
      QuoteList.Add ("Quotation", "Quotation. ")
      QuoteList.Add ("Joke", "Joke")
      QuoteList.Add ("Wisdom", "Wisdom")
      QuoteList.Add ("Saying", "Saying")
    
      If Not Page.IsPostback
        Dim ColorName as String
    
        For Each ColorName in ColorList
          ddlColorList.Items.Add(ColorName)
        Next
    
        ddlFontList.DataSource = FontList
        ddlFontList.DataBind()
        
        ddlQuoteList.DataSource = QuoteList.Keys
        ddlQuoteList.DataBind()
    
      End If
    End Sub
    
    Sub btnSelectColor_Click(sender As Object, e As EventArgs)
      lblOutputMessage.Text = QuoteList(ddlQuoteList.SelectedItem.Text)
      lblOutputMessage.ForeColor = _
        System.Drawing.Color.FromName(ddlColorList.SelectedItem.Text)
      lblOutputMessage.Font.Name = _
        ddlFontList.SelectedItem.Text
    
    End Sub

</script>
<html>
<head>
</head>
<body>
    <form runat="server">
        <p>
            Select a color from the list:<asp:DropDownList id="ddlColorList" runat="server"></asp:DropDownList>
        </p>
        <p>
            Then select a font sytle from the list: 
            <asp:DropDownList id="ddlFontList" runat="server"></asp:DropDownList>
        </p>
        <p>
            Finally, choose your output message: 
            <asp:DropDownList id="ddlQuoteList" runat="server"></asp:DropDownList>
        </p>
        <p>
            &nbsp;<asp:Button id="btnSelectColor" onclick="btnSelectColor_Click" runat="server" Text="Click here!"></asp:Button>
        </p>
        <p>
            <asp:Label id="lblOutputMessage" runat="server"></asp:Label>
        </p>
    </form>
</body>
</html>

           
       








Related examples in the same category

1.Bind Color name to asp:dropdownlist (VB.net)
2.Bind DataTable to asp:DropDownList (VB.net)
3.Bind ArrayList to asp:dropdownlist (VB.net)
4.ArrayList Data binding for asp:DropDownList (VB.net)
5.Bind arraylist elements to asp dropdown and get selected one (VB.net)
6.Use ArrayList to fill dropdown value (C#)