<%@Page Language="c#" debug="true" %>
<script runat="server" Language="c#">
void Page_Load(object source, EventArgs e)
{
Hashtable myHashtable = new Hashtable();
myHashtable["UK"] = "United Kingdom";
myHashtable["US"] = "United States";
myHashtable["DE"] = "Germany";
if (!(Page.IsPostBack))
{
foreach (DictionaryEntry Item in myHashtable)
{
ListItem newListItem = new ListItem();
newListItem.Text = Item.Value.ToString();
newListItem.Value = Item.Key.ToString();
myDropDownList.Items.Add(newListItem);
}
}
}
void Click(object source, EventArgs e)
{
myLabel.Text = myDropDownList.SelectedItem.Value;
}
</script>
<html>
<form runat="server">
<asp:dropdownlist id="myDropDownList" runat="server" />
<asp:button id="myButton" runat="server" text="OK" Onclick="Click" />
<br /><br />
<asp:Label id="myLabel" runat="server" text="" />
</form>
</html>
|