
CheckBoxList绑定数据 分组有没有可能实现 10
参考下面的代码:stringname=从数据库读取保存的那列。string[]names;names=name.Split('|');for(inti=0;i<names...
参考下面的代码:
string name=从数据库读取保存的那列。
string[] names;
names= name.Split( '| ');
for (int i = 0; i < names.Length; i++)
{
CheckBoxList1.Items.FindByValue(names[i]).Selected = true;
}
比方说CheckBoxList 六个复选框 (新闻添加,新闻删除,新闻修改 , 用户添加,用户修改,用户删除)) 能不能实现,比方说我选择新闻添加,新闻删除,用户添加,用户修改,插入后,到另一页显示,显示的时候希望排列如下:
----------------新闻-------------
口新闻添加 口新闻删除
----------------用户-------------
口用户添加 口用户修改
这个
----------------新闻-------------
----------------用户-------------
这两个东西能不能实现该如何做? 展开
string name=从数据库读取保存的那列。
string[] names;
names= name.Split( '| ');
for (int i = 0; i < names.Length; i++)
{
CheckBoxList1.Items.FindByValue(names[i]).Selected = true;
}
比方说CheckBoxList 六个复选框 (新闻添加,新闻删除,新闻修改 , 用户添加,用户修改,用户删除)) 能不能实现,比方说我选择新闻添加,新闻删除,用户添加,用户修改,插入后,到另一页显示,显示的时候希望排列如下:
----------------新闻-------------
口新闻添加 口新闻删除
----------------用户-------------
口用户添加 口用户修改
这个
----------------新闻-------------
----------------用户-------------
这两个东西能不能实现该如何做? 展开
展开全部
/// <summary>
/// 获取所有选择了的角色
/// </summary>
/// <param name="al"></param>
protected string GetCheckRole()
{
string roidStr = "";
for (int i = 0; i < chklsRoleList.Items.Count; i++)
{
if (chklsRoleList.Items[i].Selected)
{
roidStr += chklsRoleList.Items[i].Value.ToString() + ",";
}
}
if (roidStr != "")
{
roidStr = "," + roidStr;
}
return roidStr;
}
不知道有没有对你起到帮助
补充:
在表中存放就按照页面上取道的字符串存到一个字段里就行 如 1,2,3
编辑的时候,将该字段按 ','拆分存放,然后循环
CheckBoxList的值(循环之前已将CheckBoxList待选择的所有值绑定好了),在拆分存放中找到,则将其选中
例如:
/// <summary>
/// 字符串以“,”分组
/// </summary>
/// <param name="str"></param>
/// <returns></returns>
public Hashtable getStringGroup(string str)
{
string[] strings = str.Split(',');
Hashtable hs = new Hashtable();
for (int i = 0; i < strings.Length; i++)
{
hs.Add(strings[i].ToString(), strings[i].ToString());
}
return hs;
}
/// <summary>
/// 设置选择了的角色
/// </summary>
/// <param name="al"></param>
protected void SetCheckRole(string roidStr)
{
Hashtable hs = this.getStringGroup(roidStr);
for (int i = 0; i < chklsRoleList.Items.Count; i++)
{
if (hs.ContainsKey(chklsRoleList.Items[i].Value))
{
chklsRoleList.Items[i].Selected = true;
}
}
}
说道这了,不知道你明白了没?
/// 获取所有选择了的角色
/// </summary>
/// <param name="al"></param>
protected string GetCheckRole()
{
string roidStr = "";
for (int i = 0; i < chklsRoleList.Items.Count; i++)
{
if (chklsRoleList.Items[i].Selected)
{
roidStr += chklsRoleList.Items[i].Value.ToString() + ",";
}
}
if (roidStr != "")
{
roidStr = "," + roidStr;
}
return roidStr;
}
不知道有没有对你起到帮助
补充:
在表中存放就按照页面上取道的字符串存到一个字段里就行 如 1,2,3
编辑的时候,将该字段按 ','拆分存放,然后循环
CheckBoxList的值(循环之前已将CheckBoxList待选择的所有值绑定好了),在拆分存放中找到,则将其选中
例如:
/// <summary>
/// 字符串以“,”分组
/// </summary>
/// <param name="str"></param>
/// <returns></returns>
public Hashtable getStringGroup(string str)
{
string[] strings = str.Split(',');
Hashtable hs = new Hashtable();
for (int i = 0; i < strings.Length; i++)
{
hs.Add(strings[i].ToString(), strings[i].ToString());
}
return hs;
}
/// <summary>
/// 设置选择了的角色
/// </summary>
/// <param name="al"></param>
protected void SetCheckRole(string roidStr)
{
Hashtable hs = this.getStringGroup(roidStr);
for (int i = 0; i < chklsRoleList.Items.Count; i++)
{
if (hs.ContainsKey(chklsRoleList.Items[i].Value))
{
chklsRoleList.Items[i].Selected = true;
}
}
}
说道这了,不知道你明白了没?
追问
不是很明白
如何获取并绑定,下面这个没什么问题
口新闻添加 口新闻删除
口用户添加 口用户修改
我的问题最主要的是下面这个
----------------新闻-------------
----------------用户-------------
这两个东西能不能实现变成
----------------新闻-------------
口新闻添加 口新闻删除
----------------用户-------------
口用户添加 口用户修改
只要一个CheckBoxList???
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询