第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定

DropDownList的值去控制TextBox是否可編寫

標簽:
JavaScript

Web窗体上有两控件,DropDownList1,TextBox1,当DropDownList的值选择是YES的时候,TextBox1可编辑,当选择NO的时候,TextBox1的值为空,并且不能编辑,该如何实现?

效果:

 

.aspx:

View Code <%@ 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:

View Code 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;
    }
}

 

 

點擊查看更多內容
TA 點贊

若覺得本文不錯,就分享一下吧!

評論

作者其他優(yōu)質文章

正在加載中
  • 推薦
  • 評論
  • 收藏
  • 共同學習,寫下你的評論
感謝您的支持,我會繼續(xù)努力的~
掃碼打賞,你說多少就多少
贊賞金額會直接到老師賬戶
支付方式
打開微信掃一掃,即可進行掃碼打賞哦
今天注冊有機會得

100積分直接送

付費專欄免費學

大額優(yōu)惠券免費領

立即參與 放棄機會
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號

舉報

0/150
提交
取消