checkboxlist选中项目怎么入库

bj890 2007-11-05 05:16:32
for(int i=0;i<=this.CHRight.Items.Count-1;i++)
{
if(this.CHRight.Items[i].Selected)
{
role.Right+=this.CHRight.SelectedItem.Text.ToString()+",";

}
}
好像不行吧!
...全文
78 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
getnetrmb 2007-11-12
  • 打赏
  • 举报
回复
我来晚拉,给点分
bj890 2007-11-12
  • 打赏
  • 举报
回复
感谢两位。
问题已经解决了。
第二个方法比较简单点。
shinlgienls 2007-11-07
  • 打赏
  • 举报
回复
string ss="";
for(int i=0;i <=this.CHRight.Items.Count-1;i++)
{
if(this.CHRight.Items[i].Selected)
{

ss+=this.CHRight.Items[i].value+"|";
}


aspgreener 2007-11-07
  • 打赏
  • 举报
回复
你的是有问题,可以这样写
#region CheckBoxList
/// <summary>
/// 获取CheckBoxList选中的值
/// </summary>
/// <param name="cbl"></param>
/// <returns></returns>
public static string GetCheckBoxList(CheckBoxList cbl)
{
string _retval = string.Empty;

foreach (ListItem item in cbl.Items)
{
if (item.Selected)
_retval += item.Value + ",";
}

_retval = _retval.Remove(_retval.LastIndexOf(","), 1);//删除最后一个","

return _retval;
}
/// <summary>
/// 重置CheckBoxList
/// </summary>
/// <param name="cbl"></param>
public static void ResetCheckBoxList(CheckBoxList cbl)
{
foreach (ListItem item in cbl.Items)
{
item.Selected = false;
}
}

/// <summary>
/// 给CheckBoxList赋初始值
/// </summary>
/// <param name="cbl"></param>
/// <param name="strArr"></param>
public static void SetCheckBoxList(CheckBoxList cbl,string[] strArr)
{
//赋值之前先把原有的值给清除
ResetCheckBoxList(cbl);

foreach (string val in strArr)
{
if (val != "")
{
foreach (ListItem item in cbl.Items)
{
if (item.Value == val)
item.Selected = true;
}
}
}
}
#endregion

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧