日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

在.net中如何禁用或启用DropDownList的Items

發布時間:2025/5/22 编程问答 19 豆豆
生活随笔 收集整理的這篇文章主要介紹了 在.net中如何禁用或启用DropDownList的Items 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

因為網友需要不但能禁用還能可以啟用DropDownList的Items.為了不想用戶寫太多代碼。Insus.NET寫了一個類別,并讓它繼承了System.Web.UI.WebControls命名空間下的DropDownList. 可從下圖看到InsusDropDownList實例化并傳入DropDownList控件,然后實例化之后的對象,就是可以使用highlight的四個方法DisableImsByText(), DisabletemsByVue() ,EnableItemsBText(), EnableItemsByValue()。
??? InsusDropDownList類別:
???
??? InsusDropDownList
???
??? using System;
???
??? using System.Collections.Generic;
???
??? using System.Linq;
???
??? using System.Web;
???
??? using System.Web.UI.WebControls;
???
??? /// <summary>
???
??? /// Summary description for InsusDropDownList
???
??? /// </summary>
???
??? namespace Insus.NET
???
??? {
???
??? public class InsusDropDownList : DropDownList
???
??? {
???
??? DropDownList _DropDownList;
???
??? public InsusDropDownList(DropDownList dropDownList)
???
??? {
???
??? this._DropDownList = dropDownList;
???
??? }
???
??? public void DisableItemsByText(string text)
???
??? {
DisableItems(GetIndexByText(text));
???
??? }
???
??? public void EnableItemsByText(string text)
???
??? {
???
??? EnableItems(GetIndexByText(text));
???
??? }
???
??? public void DisableItemsByValue(string value)
???
??? {
???
??? DisableItems(GetIndexByValue(value));
???
??? }
???
??? public void EnableItemsByValue(string value)
???
??? {
???
??? EnableItems(GetIndexByValue(value));
???
??? }
???
??? private int GetIndexByText(string text)
???
??? {
???
??? return this._DropDownList.Items.IndexOf(this._DropDownList.Items.FindByText(text));
???
??? }
???
??? private int GetIndexByValue(string value)
???
??? {
???
??? return this._DropDownList.Items.IndexOf(this._DropDownList.Items.FindByValue(value));
???
??? }
???
??? private void DisableItems(int index)
???
??? {
???
??? if (index > -1)
???
??? this._DropDownList.Items[index].Attributes.Add("disabled", "disabled");
???
??? }
???
??? private void EnableItems(int index)
???
??? {
???
??? if (index > -1)
???
??? this._DropDownList.Items[index].Attributes.Remove("disabled");
???
??? }
???
??? }
???
??? }
??? 演示,啟用Items:
???
??? if (Request.QueryString["site"] != null)
???
??? {
???
??? InsusDropDownList obj = new InsusDropDownList(this.DropDownList1);
???
??? obj.EnableItemsByText(Request.QueryString["site"]);
???
??? }

轉載于:https://blog.51cto.com/lailjiaaie/924574

總結

以上是生活随笔為你收集整理的在.net中如何禁用或启用DropDownList的Items的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。