Effect:
. Aspx:
Copy codeThe Code is as follows: <% @ Page Language = "C #" AutoEventWireup = "true" CodeFile = "Default. aspx. cs" Inherits = "_ Default" %>
<! DOCTYPE html>
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head runat = "server">
<Title> </title>
</Head>
<Body>
<Form id = "form1" runat = "server">
<Asp: DropDownList ID = "DropDownListYesNo" runat = "server" AutoPostBack = "true" OnSelectedIndexChanged = "dropdownlistpolicselectedindexchanged">
</Asp: DropDownList>
<Asp: TextBox ID = "TextBox1" runat = "server" Enabled = "true"> </asp: TextBox>
</Form>
</Body>
</Html>
. Aspx. cs:Copy codeThe Code is as follows: using System;
Using System. Collections. Generic;
Using System. Data;
Using System. Linq;
Using System. Web;
Using System. Web. UI;
Using System. Web. UI. WebControls;
Public partial class _ Default: System. Web. UI. Page
{
Protected void Page_Load (object sender, EventArgs e)
{
If (! IsPostBack)
{
Data_Binding ();
}
}
Private void Data_Binding ()
{
This. DropDownListYesNo. DataSource = GetData (). Select (yn => new {value = yn}). ToList ();
This. DropDownListYesNo. DataTextField = "value ";
This. DropDownListYesNo. DataBind ();
}
Protected void dropdownlistincluselectedindexchanged (object sender, EventArgs e)
{
Switch (this. DropDownListYesNo. SelectedItem. Text)
{
Case "YES ":
This. TextBox1.Enabled = true;
Break;
Case "NO ":
This. TextBox1.Enabled = false;
This. TextBox1.Text = string. Empty;
Break;
}
}
Private List <string> GetData ()
{
List <string> yn = new List <string> ();
Yn. Add ("YES ");
Yn. Add ("NO ");
Return yn;
}
}