博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
CheckBox为CheckBoxList实现全选或全取消选择
阅读量:6880 次
发布时间:2019-06-27

本文共 2140 字,大约阅读时间需要 7 分钟。

某一个时候,CheckBoxList的选择太多,用户需要一个全选或全取消的功能。下面Insus.NET使用Javascript来实现它。

准备好一个对象:

MusicType
using System;using System.Collections.Generic;using System.Linq;using System.Web;/// /// Summary description for MusicType/// namespace Insus.NET{    public class MusicType    {        private int _ID;        private string _TypeName;        public int ID        {            get { return _ID; }            set { _ID = value; }        }        public string TypeName        {            get { return _TypeName; }            set { _TypeName = value; }        }        public MusicType()        {            //            // TODO: Add constructor logic here            //        }        public MusicType(int id, string typeName)        {            this._ID = id;            this._TypeName = typeName;        }            }}

填充对象:

View Code
public List
GetMusicType() { List
mt = new List
(); mt.Add(new MusicType(1, "甜密情歌")); mt.Add(new MusicType(2, "网络红歌")); mt.Add(new MusicType(3, "儿童歌曲")); mt.Add(new MusicType(4, "民族精选")); mt.Add(new MusicType(5, "校园歌曲")); mt.Add(new MusicType(6, "摇滚音乐")); mt.Add(new MusicType(7, "胎教音乐")); mt.Add(new MusicType(8, "红色名曲")); mt.Add(new MusicType(9, "串烧金曲")); mt.Add(new MusicType(10, "动慢歌曲")); return mt; }

在站点建一个aspx网页,并拉两个控件,一个是CheckBox和CheckBoxList:

View Code
全选

接下来,我们为CheckBoxList绑定数据:

View Code
using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;using Insus.NET;public partial class Default2 : System.Web.UI.Page{    protected void Page_Load(object sender, EventArgs e)    {        if (!IsPostBack)            Data_Binding();    }    private void Data_Binding()    {        this.CheckBoxListMusicType.DataSource = GetMusicType();        this.CheckBoxListMusicType.DataTextField = "TypeName";        this.CheckBoxListMusicType.DataValueField = "ID";        this.CheckBoxListMusicType.DataBind ();    }   }

最后是写Javascript代码:

View Code

ok完成,看看效果:

 

转载地址:http://irubl.baihongyu.com/

你可能感兴趣的文章
从0开始搭建微信小程序(前后端)的全过程
查看>>
小程序如何生成海报分享朋友圈
查看>>
检测后台错误
查看>>
微信小程序自定义组件
查看>>
Android Studio 和 Gradle 优化配置总结
查看>>
java8 stream实现列表去重,java8的stream 和lambda的使用实例
查看>>
iOS中通知的添加和移除
查看>>
企业分布式微服务云SpringCloud SpringBoot mybatis (一)服务的注册与发现(Eureka)...
查看>>
批量下载图片
查看>>
Java内存模型(Memory Model)
查看>>
某大型网站迁移纪实(一)
查看>>
C#进行Socket 连接发送和接收数据
查看>>
即时编辑插件-jeditable|已迁移
查看>>
Linux下CA证书服务配置
查看>>
《JMeter从入门到精通》之一——开始你的第一个JMeter脚本
查看>>
从技术到管理,艰难的转型
查看>>
如何制作Windows 8系统U盘
查看>>
Linux之cgi实现系统主机监控
查看>>
我的友情链接
查看>>
[sig09]Rendering Technology at Black Rock Studio
查看>>