佳木斯湛栽影视文化发展公司

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

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

熱門標(biāo)簽:Linux服務(wù)器 Mysql連接數(shù)設(shè)置 銀行業(yè)務(wù) 團(tuán)購網(wǎng)站 科大訊飛語音識(shí)別系統(tǒng) 服務(wù)器配置 阿里云 電子圍欄
效果:

.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 Liststring> GetData()
{
Liststring> yn = new Liststring>();
yn.Add("YES");
yn.Add("NO");
return yn;
}
}
您可能感興趣的文章:
  • jquery獲取ASP.NET服務(wù)器端控件dropdownlist和radiobuttonlist生成客戶端HTML標(biāo)簽后的value和text值
  • (asp.net c#)DropDownList綁定后顯示對(duì)應(yīng)的項(xiàng)的兩種方法
  • asp.net DropDownList自定義控件,讓你的分類更清晰
  • asp.net中不能在DropDownList中選擇多個(gè)項(xiàng) 原因分析及解決方法
  • ASP.NET MVC DropDownList數(shù)據(jù)綁定及使用詳解
  • ASP.NET筆記之 ListView 與 DropDownList的使用
  • ASP.NET服務(wù)器端控件RadioButtonList,DropDownList,CheckBoxList的取值、賦值用法
  • asp.net mvc下拉框Html.DropDownList 和DropDownListFor的常用方法
  • ASP.NET MVC中為DropDownListFor設(shè)置選中項(xiàng)的方法
  • asp.net DropDownList實(shí)現(xiàn)二級(jí)聯(lián)動(dòng)效果
  • ASP.NET中DropDownList下拉框列表控件綁定數(shù)據(jù)的4種方法
  • ASP.NET 2.0中的數(shù)據(jù)操作之七:使用DropDownList過濾的主/從報(bào)表
  • ASP.NET 2.0中的數(shù)據(jù)操作之八:使用兩個(gè)DropDownList過濾的主/從報(bào)表

標(biāo)簽:蚌埠 江蘇 棗莊 萍鄉(xiāng) 大理 衡水 廣元 衢州

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《asp.net中通過DropDownList的值去控制TextBox是否可編寫的實(shí)現(xiàn)代碼》,本文關(guān)鍵詞  ;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 收縮
    • 微信客服
    • 微信二維碼
    • 電話咨詢

    • 400-1100-266
    金乡县| 泰安市| 神农架林区| 胶州市| 长武县| 洛隆县| 旌德县| 白城市| 辽宁省| 绩溪县| 安溪县| 青冈县| 东乌珠穆沁旗| 四平市| 龙山县| 潢川县| 高陵县| 南宫市| 吴川市| 怀安县| 满洲里市| 鹤壁市| 庆城县| 合作市| 齐河县| 甘泉县| 吴桥县| 屏南县| 青冈县| 江陵县| 延边| 青田县| 于田县| 双流县| 上饶市| 濉溪县| 蕉岭县| 监利县| 江孜县| 广宗县| 新沂市|