|
|
|
|
/// <reference path="../Scripts/MicrosoftAjax.js" />
|
|
|
|
|
/// <reference path="../Scripts/jquery.min.js" />
|
|
|
|
|
|
|
|
|
|
Type.registerNamespace("nblf.ui");
|
|
|
|
|
|
|
|
|
|
nblf.ui.CheckBoxList = function (id) {
|
|
|
|
|
this.id = id;
|
|
|
|
|
this.RepeatColumns = 0;
|
|
|
|
|
this.DataSource = new Array(); //接受一个数组对象
|
|
|
|
|
this.DataTextField = "";
|
|
|
|
|
this.DataValueField = "";
|
|
|
|
|
var My = this;
|
|
|
|
|
|
|
|
|
|
//绑定数据
|
|
|
|
|
this.DataBind = function () {
|
|
|
|
|
if (this.DataTextField == "") { alert("属性DataTextField不能为空"); return; }
|
|
|
|
|
if (this.DataValueField == "") { alert("属性DataValueField不能为空"); return; }
|
|
|
|
|
var html = new Sys.StringBuilder();
|
|
|
|
|
html.append("<table border=0 cellpadding=0 cellspacing=0>");
|
|
|
|
|
html.append("<tr>");
|
|
|
|
|
var index = 0;
|
|
|
|
|
var index2 = 0;
|
|
|
|
|
$(this.DataSource).each(function () {
|
|
|
|
|
html.append("<td style='border-style: none;'><input id='" + My.id + "_Item_" + index2 + "' index='" + index2 + "' type='checkbox' text=" + this[My.DataTextField] + " value=" + this[My.DataValueField] + " /><label for='" + My.id + "_Item_" + index2 + "'>" + this[My.DataTextField] + "</label></td>");
|
|
|
|
|
if (My.RepeatColumns <= 0) return true;
|
|
|
|
|
index++;
|
|
|
|
|
index2++;
|
|
|
|
|
if (index >= My.RepeatColumns) {
|
|
|
|
|
html.append("</tr><tr>");
|
|
|
|
|
index = 0;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
if (index > 0) html.append("</tr>");
|
|
|
|
|
html.append("</table>");
|
|
|
|
|
$("#" + this.id).html(html.toString());
|
|
|
|
|
}
|
|
|
|
|
//取得所有元素
|
|
|
|
|
this.Items = function () {
|
|
|
|
|
return $("#" + this.id + " input");
|
|
|
|
|
}
|
|
|
|
|
//取得所有已选择元素
|
|
|
|
|
this.GetSelectItems = function () {
|
|
|
|
|
return $("#" + this.id + " input:checked");
|
|
|
|
|
}
|
|
|
|
|
//设置元素选择
|
|
|
|
|
this.SelectDataValue = function (DataValue) {
|
|
|
|
|
$("#" + this.id + " input[value='" + DataValue + "']").attr("checked", "checked");
|
|
|
|
|
}
|
|
|
|
|
//设置元素选择
|
|
|
|
|
this.SelectDataText = function (DataText) {
|
|
|
|
|
$("#" + this.id + " input[text='" + DataText + "']").attr("checked", "checked");
|
|
|
|
|
}
|
|
|
|
|
//设置元素选择
|
|
|
|
|
this.UnSelectDataValue = function (DataValue) {
|
|
|
|
|
$("#" + this.id + " input[value='" + DataValue + "']")[0].checked = false;
|
|
|
|
|
}
|
|
|
|
|
//设置元素选择
|
|
|
|
|
this.UnSelectDataText = function (DataText) {
|
|
|
|
|
$("#" + this.id + " input[text='" + DataText + "']")[0].checked = false;
|
|
|
|
|
}
|
|
|
|
|
//全部选择
|
|
|
|
|
this.SelectAll = function () {
|
|
|
|
|
$("#" + this.id + " :checkbox").attr("checked", "checked");
|
|
|
|
|
}
|
|
|
|
|
//取消全部选择
|
|
|
|
|
this.UnSelectAll = function () {
|
|
|
|
|
$("#" + this.id + " :checked").removeAttr("checked");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nblf.ui.CheckBoxList.registerClass('nblf.ui.CheckBoxList', null);
|