如何使用OnSelectedIndexChanged

时间:2018-01-02 17:34:46

标签: javascript c# html asp.net

我需要禁用(只读)一个文本框,并使用OnSelectedIndexChanged根据下拉列表选择将其灰显。我尝试使用以下代码,但它没有工作,我仍然能够在文本框中写入。

这是html:

       <asp:DropDownList ID="ddl" runat="server" AutoPostBack="true"
           Width="144px" Height="19px" OnSelectedIndexChanged="ddl_SelectedIndexChanged">
              <asp:ListItem Text="--Select--" Value="0" />
              <asp:ListItem Text="New York" Value= "1" />
              <asp:ListItem Text="Brooklyn" Value= "2" />
       </asp:DropDownList>



               <table>
                  <tr>
                       <td>New York:</td>
                        <td>
                          <asp:TextBox ID="txt_NY" runat="server" AutoPostBack="true" />
                        </td>
                   </tr>
                   <tr>
                        <td>Brooklyn:</td>
                        <td>
                          <asp:TextBox ID="txt_Brooklyn" runat="server"AutoPostBack="true"/>
                        </td>
                   </tr>
               </table>

这是我的代码:

 protected void ddl_SelectedIndexChanged(object sender, EventArgs e)
     {
       if (ddl.SelectedItem.Value == "1")
         {

            txt_Brooklyn.Enabled = false;

            txt_Brooklyn.BackColor = System.Drawing.Color.Gray;
         }

     }

1 个答案:

答案 0 :(得分:0)

使用class NonStaticForwardReferences { { nsf1 = 10; System.out.println(this.nsf1); // 10 nsf1 = sf1; // System.out.println(nsf1); Illegal forward reference int b = nsf1 = 20; int c = this.nsf1; System.out.println(c); // 20 // why variable 'c' is initialized to 20 when used with 'this' reference // instead of showing illegal forward reference, how it works in the background? } int nsf1 = nsf2 = 30; int nsf2; static int sf1 = 5; public static void main(String[] args) {} } 属性,这样会自动灰显

ReadOnly