Jump to content

[SOLVED] ASP.NET - Hashtable Question


twilitegxa

Recommended Posts

Is there a way to have a hash table as a select list that, when the user selects an option, it populates a paragraph for that option in a label? I have the code that displays the selected item's value, but I don't know how to add a paragraph or sentence that doesn't show up in the select list. I want a few options, and then wen they pick an option, it says something else (like something that wasn't in the list, like a paragraph or sentence about the option picked). Can anyone help with that?

 

I'm working with this:

 

<script  runat="server">
sub Page_Load
if Not Page.IsPostBack then
   dim mycountries=New Hashtable
            mycountries.Add("G", "Grooming")
            mycountries.Add("H", "Health")
            mycountries.Add("F", "Feeding")
            mycountries.Add("E", "Exercise")
            mycountries.Add("S", "Species")
   dd.DataSource=mycountries
   dd.DataValueField="Key"
   dd.DataTextField="Value"
   dd.DataBind()
end if
end sub

sub displayMessage(s as Object,e As EventArgs)
lbl1.text="Your favorite country is: " & dd.SelectedItem.Text
end sub
</script>

<html>
<body>

<form id="Form1" runat="server">
<asp:DropDownList id="dd" runat="server"
AutoPostBack="True" onSelectedIndexChanged="displayMessage" />
<p><asp:label id="lbl1" runat="server" /></p>
</form>

</body>
</html>

 

How can I do this? Any help?

 

Link to post
Share on other sites

I figured out a way to do what I wanted:

 

<script  runat="server">
sub Page_Load
if Not Page.IsPostBack then
            Dim petInformation = New Hashtable
            petInformation.Add("G", "Grooming")
            petInformation.Add("H", "Health")
            petInformation.Add("F", "Feeding")
            petInformation.Add("E", "Exercise")
            petInformation.Add("S", "Species")
            dd.DataSource = petInformation
   dd.DataValueField="Key"
   dd.DataTextField="Value"
   dd.DataBind()
end if
end sub

    Sub displayMessage(ByVal s As Object, ByVal e As EventArgs)
        If dd.SelectedItem.Text = "Grooming" Then
            lbl1.Text = "<p>Grooming your pet is specific to each kind of pet. For<br> example, you can give your dog a bath in the bathtub, while<br> cats require a special foaming cleanser instead. Some pets<br> require more grooming than others, so be sure to read the <br>information thoroughly. Some grooming might even be <br>covered by a pet's insurance, especially those that require <br>excessive grooming. Choose your pet type below for more<br> specific information:</p>"
        ElseIf dd.SelectedItem.Text = "Health" Then
            lbl1.Text = "Keeping your pet healthy is very important. Ensuring they <br>have the proper nutrition for their age, exercise, and <br>supplements is an important to ensure good health for your <br>pet. Choose your pet type below for appropriate preventive <br>and supplemental health products and exercise we <br>recommend:"
        ElseIf dd.SelectedItem.Text = "Feeding" Then
            lbl1.Text = "Feeding your pet the proper amounts is very crucial in <br>keeping your pet at a healthy weight. Too much can cause <br>him to be overweight, while too little can cause him to be <br>malnourished. Choose your pet type below for charts <br>showing proper nutrition according to age and weight:"
        ElseIf dd.SelectedItem.Text = "Exercise" Then
            lbl1.Text = "Getting the right amount of exercise ensures that your pet<br> stays healthy and doesn't become overweight. This also <br>helps to keep his joints and muscles strong and in good <br>condition. Choose your pet type below to see some <br>recommendations for exercise for your pet:"
        ElseIf dd.SelectedItem.Text = "Species" Then
            lbl1.Text = "Each pet has unique characteristics. Some pets <br>require special care because of their species. Others, a <br>special diet. Knowing more about your pet will help <br>you to take better care of him. Select your pet's species<br> below to learn more about your pet:"
        End If
    End Sub
</script>

<html>
<body>

<form id="Form1" runat="server">
<asp:DropDownList id="dd" runat="server"
AutoPostBack="True" onSelectedIndexChanged="displayMessage" />
<p><asp:label id="lbl1" runat="server" /></p>
</form>

</body>
</html>

Link to post
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.