最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

asp.net中通過(guò)DropDownList的值去控制TextBox是否可編寫的實(shí)現(xiàn)代碼

 更新時(shí)間:2012年11月06日 11:10:53   作者:  
Web窗體上有兩控件,DropDownList1,TextBox1,當(dāng)DropDownList的值選擇是YES的時(shí)候,TextBox1可編輯,當(dāng)選擇NO的時(shí)候,TextBox1的值為空,并且不能編輯,該如何實(shí)現(xiàn)
效果:

.aspx:
復(fù)制代碼 代碼如下:

<%@ 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="DropDownList1_SelectedIndexChanged">
</asp:DropDownList>
<asp:TextBox ID="TextBox1" runat="server" Enabled="true"></asp:TextBox>
</form>
</body>
</html>

.aspx.cs:
復(fù)制代碼 代碼如下:

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 DropDownList1_SelectedIndexChanged(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;
}
}

相關(guān)文章

最新評(píng)論

丘北县| 渝中区| 聂荣县| 友谊县| 漳州市| 天长市| 滨州市| 米易县| 双牌县| 光泽县| 忻州市| 江川县| 江口县| 万载县| 义乌市| 抚顺市| 德格县| 高密市| 乌什县| 博爱县| 徐水县| 巴东县| 临安市| 乌兰县| 阳山县| 左云县| 南澳县| 阿克| 永顺县| 河间市| 社旗县| 绍兴县| 长宁县| 保德县| 宿州市| 澄江县| 香河县| 长沙市| 江达县| 屯门区| 宜章县|