代码如下:
Default.aspx
1
<%
@ Page Language
=
"
C#
"
AutoEventWireup
=
"
true
"
CodeFile
=
"
Default.aspx.cs
"
Inherits
=
"
_Default
"
%>
2
3 <! DOCTYPE html PUBLIC " -//W3C//DTD XHTML 1.0 Transitional//EN " " http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd " >
4
5 < html xmlns = " http://www.w3.org/1999/xhtml " >
6 < head runat = " server " >
7 < title > Untitled Page </ title >
8 </ head >
9 < body >
10 < form id = " form1 " runat = " server " >
11 < div >
12 < asp:Label ID = " Label1 " runat = " server " Text = " Label " ></ asp:Label >
13 < asp:DropDownList ID = " DropDownList1 " runat = " server " OnSelectedIndexChanged = " DropDownList1_SelectedIndexChanged " >
14 < asp:ListItem > 123 </ asp:ListItem >
15 < asp:ListItem > 456 </ asp:ListItem >
16 < asp:ListItem > 789 </ asp:ListItem >
17 < asp:ListItem > abc </ asp:ListItem >
18 </ asp:DropDownList >
19 </ div >
20 </ form >
21 </ body >
22 </ html >
23
2
3 <! DOCTYPE html PUBLIC " -//W3C//DTD XHTML 1.0 Transitional//EN " " http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd " >
4
5 < html xmlns = " http://www.w3.org/1999/xhtml " >
6 < head runat = " server " >
7 < title > Untitled Page </ title >
8 </ head >
9 < body >
10 < form id = " form1 " runat = " server " >
11 < div >
12 < asp:Label ID = " Label1 " runat = " server " Text = " Label " ></ asp:Label >
13 < asp:DropDownList ID = " DropDownList1 " runat = " server " OnSelectedIndexChanged = " DropDownList1_SelectedIndexChanged " >
14 < asp:ListItem > 123 </ asp:ListItem >
15 < asp:ListItem > 456 </ asp:ListItem >
16 < asp:ListItem > 789 </ asp:ListItem >
17 < asp:ListItem > abc </ asp:ListItem >
18 </ asp:DropDownList >
19 </ div >
20 </ form >
21 </ body >
22 </ html >
23
Default.aspx.cs
1
using
System;
2 using System.Data;
3 using System.Configuration;
4 using System.Web;
5 using System.Web.Security;
6 using System.Web.UI;
7 using System.Web.UI.WebControls;
8 using System.Web.UI.WebControls.WebParts;
9 using System.Web.UI.HtmlControls;
10
11 public partial class _Default : System.Web.UI.Page
12 {
13 protected void Page_Load(object sender, EventArgs e)
14 {
15
16 }
17 protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
18 {
19 Label1.Text = DropDownList1.SelectedValue;
20 }
21}
22
2 using System.Data;
3 using System.Configuration;
4 using System.Web;
5 using System.Web.Security;
6 using System.Web.UI;
7 using System.Web.UI.WebControls;
8 using System.Web.UI.WebControls.WebParts;
9 using System.Web.UI.HtmlControls;
10
11 public partial class _Default : System.Web.UI.Page
12 {
13 protected void Page_Load(object sender, EventArgs e)
14 {
15
16 }
17 protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
18 {
19 Label1.Text = DropDownList1.SelectedValue;
20 }
21}
22