您现在的位置是:网站首页> 编程资料编程资料
如何为CheckBoxList和RadioButtonList添加滚动条_实用技巧_
2023-05-24
360人已围观
简介 如何为CheckBoxList和RadioButtonList添加滚动条_实用技巧_
如何给CheckBoxList和RadioButtonList添加滚动条?
继承基类CheckBoxList和RadioButtonList,添加滚动属性,重写Render方法即可。
属性列表:
#region 滚动控制 private bool _ShowScrollBar = false; ////// 显示滚动条 /// [ System.ComponentModel.Description("是否显示显示滚动条") , System.ComponentModel.DefaultValue(false) , System.ComponentModel.Category("滚动条设置") , System.ComponentModel.Bindable(System.ComponentModel.BindableSupport.Yes) ] public bool ShowScrollBar { get { return _ShowScrollBar; } set { _ShowScrollBar = value; } } private Overflow _OverflowY = Overflow.auto; ////// 竖直滚动条 /// [ System.ComponentModel.Description("竖直滚动条") , System.ComponentModel.DefaultValue(Overflow.auto) , System.ComponentModel.Category("滚动条设置") , System.ComponentModel.Bindable(System.ComponentModel.BindableSupport.Yes) ] public Overflow OverflowY { get { return _OverflowY; } set { _OverflowY = value; } } private Overflow _OverflowX = Overflow.auto; ////// 水平滚动条 /// [ System.ComponentModel.Description("水平滚动条") , System.ComponentModel.DefaultValue(Overflow.auto) , System.ComponentModel.Category("滚动条设置") , System.ComponentModel.Bindable(System.ComponentModel.BindableSupport.Yes) ] public Overflow OverflowX { get { return _OverflowX; } set { _OverflowX = value; } } private Unit _ScrollHeight = Unit.Parse("0px"); ////// 滚动高度 /// [ System.ComponentModel.Description("滚动高度") , System.ComponentModel.Category("滚动条设置") , DefaultValue("0px") , System.ComponentModel.Bindable(System.ComponentModel.BindableSupport.Yes) ] public Unit ScrollHeight { get { return _ScrollHeight; } set { _ScrollHeight = value; } } private Unit _ScrollWidth = Unit.Parse("0px"); ////// 滚动宽度 /// [ System.ComponentModel.Description("滚动宽度") , System.ComponentModel.Category("滚动条设置") , DefaultValue("0px") , System.ComponentModel.Bindable(System.ComponentModel.BindableSupport.Yes) ] public Unit ScrollWidth { get { return _ScrollWidth; } set { _ScrollWidth = value; } } private string _ScrollCssClass = ""; ////// 滚动样式设置 /// [ System.ComponentModel.Description("滚动样式设置") , System.ComponentModel.Category("滚动条设置") , System.ComponentModel.DefaultValue("") , System.ComponentModel.Bindable(System.ComponentModel.BindableSupport.Yes) ] public string ScrollCssClass { get { return _ScrollCssClass; } set { _ScrollCssClass = value; } } #region 书写标签 void WriteBeginSpan(HtmlTextWriter writer) { if (this._ShowScrollBar) { StringBuilder strSpan = new StringBuilder(); strSpan.Append(""); writer.Write(strSpan.ToString()); } } void WriteEndSpan(HtmlTextWriter writer) { if (this._ShowScrollBar) { writer.Write(""); } } #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 } 以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
您可能感兴趣的文章:
- ASP.NET中RadioButtonList绑定后台数据后触发点击事件
- ASP.NET服务器端控件RadioButtonList,DropDownList,CheckBoxList的取值、赋值用法
- jquery判断RadioButtonList和RadioButton中是否有选中项示例
- js获取RadioButtonList的Value/Text及选中值等信息实现代码
- RadioButtonList绑定图片及泛型Dictionary应用
- javascript判断是否有对RadioButtonList选项选择
- ASP.NET jQuery 实例16 通过控件CustomValidator验证RadioButtonList
- JQuery中对服务器控件 DropdownList, RadioButtonList, CheckboxList的操作总结
- jquery获取ASP.NET服务器端控件dropdownlist和radiobuttonlist生成客户端HTML标签后的value和text值
- ASP.NET控件之RadioButtonList详解
相关内容
- .NET Core Windows环境安装配置教程_实用技巧_
- VS2015开发环境的安装和配置_实用技巧_
- vim vax 快捷键大全_实用技巧_
- asp.net基于替换模版页的形式生成静态页的方法_实用技巧_
- ASP.NET中URL Routing和IIS上URL Rewriting的区别_自学过程_
- ASP.NET MVC中使用jQuery时的浏览器缓存问题详解_实用技巧_
- asp.net(C#)实现功能强大的时间日期处理类完整实例_实用技巧_
- asp.net使用Socket.Send发送信息及Socket.SendFile传输文件的方法_实用技巧_
- ASP.NET MVC3 SEO优化:利用Routing特性提高站点权重_实用技巧_
- 最锋利的Visual Studio Web开发工具扩展:Web Essentials使用详解_实用技巧_
