让保存和反绑定更加简单!

CheckBoxList 拓展_ide



CheckBoxList 拓展_i++_02


新建 ZCheckBoxList类:

using System.Web.UI.WebControls;
namespace Business
{
public class ZCheckBoxList : CheckBoxList
{
/// 2011-6-19 曾祥展
/// 假如勾2,3,4 則SelectedValue="2,3,4"
/// </remarks>
public override string SelectedValue
{
get
{
string _ReturnValue = "";
this.EnsureChildControls();
for (int i = 0; i < this.Items.Count; i++)
{
if (this.Items[i].Selected == true)
{
_ReturnValue += this.Items[i].Value + ",";
}
}
if (!string.IsNullOrEmpty(_ReturnValue))
{
_ReturnValue = _ReturnValue.TrimEnd(',');
}
else
{
return string.Empty;
}
return _ReturnValue;
}
set
{
if (value == null)
{
value = string.Empty;
}
string _ReturnValue = "";
this.EnsureChildControls();
_ReturnValue = value;
for (int i = 0; i < this.Items.Count; i++)
{
this.Items[i].Selected = false;
}
if (_ReturnValue.Trim().Length != 0)
{
string[] ReturnValue1 = _ReturnValue.Split(',');
// 1,2,3
for (int intItem = 0; intItem <= ReturnValue1.Length - 1; intItem++)
{
for (int i = 0; i < this.Items.Count; i++)
{
if (ReturnValue1[intItem] == this.Items[i].Value)
{
this.Items[i].Selected = true;
break;
}
}
}
}
}
}
}
}

using System.Web.UI.WebControls;
namespace Business
{
public class ZCheckBoxList : CheckBoxList
{
/// 2011-6-19 曾祥展
/// 假如勾2,3,4 則SelectedValue="2,3,4"
/// </remarks>
public override string SelectedValue
{
get
{
string _ReturnValue = "";
this.EnsureChildControls();
for (int i = 0; i < this.Items.Count; i++)
{
if (this.Items[i].Selected == true)
{
_ReturnValue += this.Items[i].Value + ",";
}
}
if (!string.IsNullOrEmpty(_ReturnValue))
{
_ReturnValue = _ReturnValue.TrimEnd(',');
}
else
{
return string.Empty;
}
return _ReturnValue;
}
set
{
if (value == null)
{
value = string.Empty;
}
string _ReturnValue = "";
this.EnsureChildControls();
_ReturnValue = value;
for (int i = 0; i < this.Items.Count; i++)
{
this.Items[i].Selected = false;
}
if (_ReturnValue.Trim().Length != 0)
{
string[] ReturnValue1 = _ReturnValue.Split(',');
// 1,2,3
for (int intItem = 0; intItem <= ReturnValue1.Length - 1; intItem++)
{
for (int i = 0; i < this.Items.Count; i++)
{
if (ReturnValue1[intItem] == this.Items[i].Value)
{
this.Items[i].Selected = true;
break;
}
}
}
}
}
}
}
}