.NET 根据下拉列表选择不同的值动态改变对应textbox的属性

来源:互联网 发布:红警3起义时刻兵种数据 编辑:程序博客网 时间:2024/05/29 20:02

前台下拉列表

 <asp:DropDownList ID="DropDownList2" runat="server" Width="110px" AutoPostBack="True" onselectedindexchanged="DropDownList2_Changed">        <asp:ListItem Value="01" Text="否"></asp:ListItem>        <asp:ListItem Value="02" Text="是"></asp:ListItem> </asp:DropDownList>

AutoPostBack=”True”回传服务器此控件值更改后与服务器交互,漏掉就没反应了。
前台textbox

<asp:TextBox ID="Costs" runat="server" Width="106px"  Enabled = false  ></asp:TextBox >

后台定义

protected void DropDownList2_Changed(object sender, EventArgs e) {    if (DropDownList2.SelectedValue.ToString().Equals("01"))    {        Costs.Enabled = false;    }    else {        Costs.Enabled = true;    }}
0 0
原创粉丝点击