Let’s say you have a DropDownList which has records either from a database or some other data. You not only have a text value for the DropDownList which may relate to another datastore somewhere.
This sample creates a DropDownList with a numeric value and a text item for each entry in the list. Using that information, when selected, a label shows the value and the text, and an HTML link is created, using the value of the selected item in the DropDownList.
<html>
<head>
<meta name=”GENERATOR” Content=”ASP Express 2.0″>
<title>DropDownList – Values, Text and Querystrings</title>
<script language=”VB” runat=”server”>
Sub Page_Load(Source as Object, E as EventArgs)
Dim intID as Integer
intID= request.Querystring(“details”)
if intID>0 then
form1.visible=”false”
label1.visible=”false”
Select Case intID
Case 1
literal1.text=”John is 23 years old and lives in Cleveland and he’s unemployed”
Case 2
literal1.text=”Chris is 24 years old and lives in Dallas and he’s a programmer”
Case 3
literal1.text=”David is 28 years old and lives in Los Angeles and is a great guitar player”
Case 4
literal1.text=”Eric is 24 years old and lives in Oklahoma City and he works for the city”
End Select
Literal1.text=Literal1.text & “<br><a href=”"ddltest.aspx”">Start Over</a>”
End If
End Sub
Sub doit(Source as Object, E as EventArgs)
if ddl.selecteditem.text<>”" then
label1.text=”Value = ” & ddl.selecteditem.value & ” – Text = ” & ddl.selecteditem.text
Literal1.text=”<a href=”"ddltest.aspx?details=” & ddl.selecteditem.value & “”">Get Details for ” & ddl.selecteditem.text & “</a>”
End If
End Sub
</script>
</head>
<body>
<Form id=”Form1″ runat=”server”>
<asp:dropdownlist id=”ddl” runat=”server”>
<asp:listitem value=”1″ selected=”true”>John</asp:listitem>
<asp:listitem value=”2″>Chris</asp:listitem>
<asp:listitem value=”3″>David</asp:listitem>
<asp:listitem value=”4″>Eric</asp:listitem>
</asp:dropdownlist> <asp:Button id=”button1″ Text=”Get it” onclick=”doit” runat=”server” />
<br>
<asp:Label ID=”label1″ runat=”server” /><br>
</Form>
<asp:Literal ID=”Literal1″ runat=”server” />
</body>
</html>