DropDownList TextBox
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>
<style type="text/css">
.t1
{
width:200px;
position:absolute;
}
.d1
{
width:217px;
height:22px;
clip:rect(auto auto auto 200px);
position:absolute;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server" CssClass="t1" ></asp:TextBox>
<asp:DropDownList ID="DropDownList1" runat="server" CssClass="d1" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged" AutoPostBack="true">
<asp:ListItem Text="a" Value="1"></asp:ListItem>
<asp:ListItem Text="b" Value="2"></asp:ListItem>
<asp:ListItem Text="c" Value="3"></asp:ListItem>
</asp:DropDownList>
</div>
</form>
</body>
</html>
C#:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Test_tsCombobox : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
TextBox1.Text = DropDownList1.SelectedItem.Text;
}
}

沒有留言:
張貼留言