某一个时候,CheckBoxList的选择太多,用户需要一个全选或全取消的功能。下面使用Javascript来实现它。
using
System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
/// <summary>
/// Summary description for MusicType
/// </summary>
namespace Insus.NET
{
p
ublic class MusicType
{
PRivate int _ID;
private string _TypeN
ame;
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;
}
}
}
public List<
;musicType> GetMusicType()
{
List<MusicType> mt = new List<MusicType>();
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;
}
全选<asp:CheckBox ID="CheckBoxAll" runat="server" onClick="javascript:Check_Uncheck_All(this);" /><
br />
<asp:CheckBoxList ID="CheckBoxListMusicType" runat="server" RepeatColumns="3" RepeatDirection="Horizontal" Width="300"></asp:CheckBoxList>
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, Event
args e)
{
if (!IsPostBack)
Data_Binding();
}
private void Data_Binding()
{
this.CheckBoxListMusicType.DataSource = GetMusicType();
this.CheckBoxListMusicType.DataTextField = "TypeName";
this.CheckBoxListMusicType.DataVal
UEFIeld = "ID";
this.CheckBoxListMusicType.DataBind ();
}
}
var input = cbl.