webform1.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="test5_2.WebForm1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" Text="密码提示问题:"></asp:Label>
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged" Width="240px">
<asp:ListItem Value="0">请任选一项</asp:ListItem>
<asp:ListItem Value="1">我的出生地</asp:ListItem>
<asp:ListItem Value="2">我母亲的名字</asp:ListItem>
<asp:ListItem Value="3">我父亲的名字</asp:ListItem>
</asp:DropDownList>
<br />
<asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>
<asp:TextBox ID="TextBox1" runat="server" Width="99px"></asp:TextBox>
</div>
</form>
</body>
</html>
webform1.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace test5_2
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Label2.Text = "答案:";
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
switch (DropDownList1.SelectedValue)
{
case "1":
Label2.Text = DropDownList1.Items[DropDownList1.SelectedIndex].Text+":";
break;
case "2":
Label2.Text = DropDownList1.Items[DropDownList1.SelectedIndex].Text + ":";
break;
case "3":
Label2.Text = DropDownList1.Items[DropDownList1.SelectedIndex].Text + ":";
break;
}
}
}
}