国产探花免费观看_亚洲丰满少妇自慰呻吟_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ā)表
主站蜘蛛池模板: 乡城县| 信丰县| 西城区| 施秉县| 普安县| 怀化市| 固原市| 佛山市| 隆化县| 那坡县| 宝清县| 修水县| 金阳县| 巴彦淖尔市| 平邑县| 平泉县| 岳阳市| 元朗区| 株洲市| 佛教| 湖口县| 浠水县| 绵阳市| 加查县| 阿勒泰市| 萍乡市| 夏河县| 钟祥市| 凤城市| 漾濞| 甘洛县| 九龙城区| 开原市| 监利县| 武邑县| 怀化市| 和静县| 安新县| 时尚| 澄江县| 浪卡子县|