在DROPDOWNLIST里绑定ID,通过选择ID值在Textbox中显示对应ID的name值应该怎么做?不用button.
展开全部
用DROPDOWNLIST里的SelectedIndexChanged事件就可以了,注意再将DROPDOWNLIST属性AutoPostBack设为"True",然后在 SelectedIndexChanged事件里写例如:TextBox1.Text = DropDownList1.SelectedItem.Text;
一个例子给你:
前台html代码:
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True"
onselectedindexchanged="DropDownList1_SelectedIndexChanged">
<asp:ListItem Value="3">澳门</asp:ListItem>
<asp:ListItem Value="1">如皋</asp:ListItem>
<asp:ListItem Value="2">南通</asp:ListItem>
</asp:DropDownList>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
后台代码:
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
TextBox1.Text = DropDownList1.SelectedItem.Text;
}
一个例子给你:
前台html代码:
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True"
onselectedindexchanged="DropDownList1_SelectedIndexChanged">
<asp:ListItem Value="3">澳门</asp:ListItem>
<asp:ListItem Value="1">如皋</asp:ListItem>
<asp:ListItem Value="2">南通</asp:ListItem>
</asp:DropDownList>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
后台代码:
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
TextBox1.Text = DropDownList1.SelectedItem.Text;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询