110,580
社区成员
发帖
与我相关
我的任务
分享
<body>
<form id="form1" runat="server">
<div>
<asp:DropDownList ID="DropDownList1" runat="server" OnTextChanged="DropDownList1_TextChanged"
<asp:ListItem Value="你是1号">你是1号</asp:ListItem>
<asp:ListItem Value="你是2号">你是2号</asp:ListItem>
<asp:ListItem Value="你是3号">你是3号</asp:ListItem>
<asp:ListItem Value="你是4号">你是4号</asp:ListItem>
</asp:DropDownList>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</div>
</form>
</body>
protected void DropDownList1_TextChanged(object sender, EventArgs e)
{
this.TextBox1.Text = this.DropDownList1.SelectedValue;
}
1:首先读取数据库,取出要绑定的数据信息。
绑定到DropDownList中:
this.DropDownList.DataSource = 数据源
this.DropDownList.DataTextField = "ColumnName1"; //显示的字段(text)
this.DropDownList.DataValueField = "ColumnName2";//Value字段
this.DropDownList.DataBind();// 绑定
2:TextBox1中显示
DropDownList的AutoPostBack属性设置为True;
protected void DropDownList_SelectedIndexChanged(object sender, EventArgs e)
{
this.TextBox1.Text = this.DropDownList1.SelectedValue.tostring();
}
this.TextBox1.Text = this.DropDownList1.SelectedValue;