国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

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

2024-07-10 13:23:31
字體:
供稿:網(wǎng)友
效果:

asp.net中通過DropDownList的值去控制TextBox是否可編寫的實(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 runat="server">
<asp:DropDownList runat="server" AutoPostBack="true" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
</asp:DropDownList>
<asp:TextBox 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;
}
}

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 石棉县| 金堂县| 左贡县| 泾川县| 高尔夫| 瑞金市| 西畴县| 四平市| 开封市| 绵阳市| 拉孜县| 砚山县| 华池县| 墨脱县| 沂源县| 建湖县| 绥棱县| 双柏县| 方山县| 册亨县| 康平县| 湘潭市| 夏邑县| 镇远县| 普安县| 阆中市| 衡东县| 英吉沙县| 酒泉市| 巴里| 京山县| 儋州市| 卓尼县| 鹤峰县| 牡丹江市| 平阴县| 沙雅县| 灵丘县| 宣城市| 湖北省| 株洲市|