如何為CheckBoxList和RadioButtonList添加滾動條
如何給CheckBoxList和RadioButtonList添加滾動條?
繼承基類CheckBoxList和RadioButtonList,添加滾動屬性,重寫Render方法即可。
屬性列表:
#region 滾動控制
private bool _ShowScrollBar = false;
/// <summary>
/// 顯示滾動條
/// </summary>
[
System.ComponentModel.Description("是否顯示顯示滾動條")
, System.ComponentModel.DefaultValue(false)
, System.ComponentModel.Category("滾動條設(shè)置")
, System.ComponentModel.Bindable(System.ComponentModel.BindableSupport.Yes)
]
public bool ShowScrollBar
{
get { return _ShowScrollBar; }
set { _ShowScrollBar = value; }
}
private Overflow _OverflowY = Overflow.auto;
/// <summary>
/// 豎直滾動條
/// </summary>
[
System.ComponentModel.Description("豎直滾動條")
, System.ComponentModel.DefaultValue(Overflow.auto)
, System.ComponentModel.Category("滾動條設(shè)置")
, System.ComponentModel.Bindable(System.ComponentModel.BindableSupport.Yes)
]
public Overflow OverflowY
{
get { return _OverflowY; }
set { _OverflowY = value; }
}
private Overflow _OverflowX = Overflow.auto;
/// <summary>
/// 水平滾動條
/// </summary>
[
System.ComponentModel.Description("水平滾動條")
, System.ComponentModel.DefaultValue(Overflow.auto)
, System.ComponentModel.Category("滾動條設(shè)置")
, System.ComponentModel.Bindable(System.ComponentModel.BindableSupport.Yes)
]
public Overflow OverflowX
{
get { return _OverflowX; }
set { _OverflowX = value; }
}
private Unit _ScrollHeight = Unit.Parse("0px");
/// <summary>
/// 滾動高度
/// </summary>
[
System.ComponentModel.Description("滾動高度")
, System.ComponentModel.Category("滾動條設(shè)置")
, DefaultValue("0px")
, System.ComponentModel.Bindable(System.ComponentModel.BindableSupport.Yes)
]
public Unit ScrollHeight
{
get { return _ScrollHeight; }
set { _ScrollHeight = value; }
}
private Unit _ScrollWidth = Unit.Parse("0px");
/// <summary>
/// 滾動寬度
/// </summary>
[
System.ComponentModel.Description("滾動寬度")
, System.ComponentModel.Category("滾動條設(shè)置")
, DefaultValue("0px")
, System.ComponentModel.Bindable(System.ComponentModel.BindableSupport.Yes)
]
public Unit ScrollWidth
{
get { return _ScrollWidth; }
set { _ScrollWidth = value; }
}
private string _ScrollCssClass = "";
/// <summary>
/// 滾動樣式設(shè)置
/// </summary>
[
System.ComponentModel.Description("滾動樣式設(shè)置")
, System.ComponentModel.Category("滾動條設(shè)置")
, System.ComponentModel.DefaultValue("")
, System.ComponentModel.Bindable(System.ComponentModel.BindableSupport.Yes)
]
public string ScrollCssClass
{
get { return _ScrollCssClass; }
set { _ScrollCssClass = value; }
}
#region 書寫標(biāo)簽
void WriteBeginSpan(HtmlTextWriter writer)
{
if (this._ShowScrollBar)
{
StringBuilder strSpan = new StringBuilder();
strSpan.Append("<span ");
strSpan.Append(string.Format("style='overflow-y:{0};overflow-x:{1};",
System.Enum.GetName(typeof(Overflow), this._OverflowY),
System.Enum.GetName(typeof(Overflow), this._OverflowX)));
if (this._ScrollHeight.ToString() != "0px")
{
strSpan.Append(string.Format("height:{0};", this._ScrollHeight));
}
if (this._ScrollWidth.ToString() != "0px")
{
strSpan.Append(string.Format("width:{0};", this._ScrollWidth));
}
strSpan.Append("';");
if (!string.IsNullOrEmpty(_ScrollCssClass))
{
strSpan.Append(string.Format(" class='{0}'", _ScrollCssClass));
}
strSpan.Append(">");
writer.Write(strSpan.ToString());
}
}
void WriteEndSpan(HtmlTextWriter writer)
{
if (this._ShowScrollBar)
{
writer.Write("</span>");
}
}
#endregion
#endregion
重寫Render方法:
protected override void Render(HtmlTextWriter writer)
{
this.WriteBeginSpan(writer);
base.Render(writer);
this.WriteEndSpan(writer);
}
就這樣就可以了。
還要定義一個枚舉:
public enum Overflow
{
auto = 0,
hidden = 1,
scroll = 2,
visible = 3,
inherit = 4
}
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- ASP.NET中RadioButtonList綁定后臺數(shù)據(jù)后觸發(fā)點(diǎn)擊事件
- ASP.NET服務(wù)器端控件RadioButtonList,DropDownList,CheckBoxList的取值、賦值用法
- jquery判斷RadioButtonList和RadioButton中是否有選中項示例
- js獲取RadioButtonList的Value/Text及選中值等信息實(shí)現(xiàn)代碼
- RadioButtonList綁定圖片及泛型Dictionary應(yīng)用
- javascript判斷是否有對RadioButtonList選項選擇
- ASP.NET jQuery 實(shí)例16 通過控件CustomValidator驗證RadioButtonList
- JQuery中對服務(wù)器控件 DropdownList, RadioButtonList, CheckboxList的操作總結(jié)
- jquery獲取ASP.NET服務(wù)器端控件dropdownlist和radiobuttonlist生成客戶端HTML標(biāo)簽后的value和text值
- ASP.NET控件之RadioButtonList詳解
相關(guān)文章
.NET中的MassTransit分布式應(yīng)用框架詳解
MassTransit是一款優(yōu)秀的分布式應(yīng)用框架,可作為分布式應(yīng)用的消息總線,也可以用作單體應(yīng)用的事件總線,這篇文章主要介紹了.NET中的MassTransit分布式應(yīng)用框架,需要的朋友可以參考下2022-10-10
asp.net基于HashTable實(shí)現(xiàn)購物車的方法
這篇文章主要介紹了asp.net基于HashTable實(shí)現(xiàn)購物車的方法,涉及asp.net中HashTable結(jié)合session實(shí)現(xiàn)購物車功能的相關(guān)技巧,具有一定參考借鑒價值,需要的朋友可以參考下2015-12-12
asp.net開發(fā)中常見公共捕獲異常方式總結(jié)(附源碼)
這篇文章主要介紹了asp.net開發(fā)中常見公共捕獲異常方式總結(jié),結(jié)合實(shí)例形式較為詳細(xì)的分析了asp.net捕獲異常的相關(guān)技巧,并提供了完整的實(shí)例代碼供讀者下載參考,需要的朋友可以參考下2015-11-11
asp.net下使用Request.From獲取非服務(wù)器控件的值的方法
asp.net下使用Request.From獲取非服務(wù)器控件的值的方法,需要的朋友可以參考下。2010-03-03
使用?HttpReports?監(jiān)控?.NET?Core?應(yīng)用程序的方法
這篇文章主要介紹了使用?HttpReports?監(jiān)控?.NET?Core?應(yīng)用程序的方法,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2021-03-03

