CheckBoxList

DoubleMars 2008-12-09 02:46:26
前台:
<asp:CheckBoxList ID="CheckBoxList1" runat="server" RepeatColumns="5">
<asp:ListItem Value="a">aaaa</asp:ListItem>
<asp:ListItem Value="b">bbbb</asp:ListItem>
<asp:ListItem Value="c">cccc</asp:ListItem>
<asp:ListItem Value="d">dddd</asp:ListItem>
<asp:ListItem Value="e">eeee</asp:ListItem>
................
<asp:ListItem Value="z">zzzz</asp:ListItem>
</asp:CheckBoxList>
后台:
string[] str = new string{'a','c','j','h','r'}

如何在后台选中 CheckBoxList1的ListItem的Value = str[i]?

在线急等!





...全文
70 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
wljie103 2008-12-09
  • 打赏
  • 举报
回复

using System.Collections.Generic;
private List<String> _listChk = new List<string>();

private List<String> _listChk = new List<string>();

protected void Page_Load(object sender, EventArgs e)
{
string[] str = { "a", "c", "j", "h", "r" };
for (int j = 0; j < str.Length; j++)
{
_listChk.Add(str[j].ToString());
}

for (int i = 0; i < CheckBoxList1.Items.Count; i++)
{
if (_listChk.Contains(CheckBoxList1.Items[i].Value))
{
CheckBoxList1.Items[i].Selected = true;
}
}
}
migang 2008-12-09
  • 打赏
  • 举报
回复
没看董意思。。

如果要设置CheckBoxList1的值为str[i] :CheckBoxList1.SelectedValue=str[i]即可。
Wayne 2008-12-09
  • 打赏
  • 举报
回复

string[] str = { "a", "c", "j", "h", "r" };
for (int i = 0; i < CheckBoxList1.Items.Count; i++)
{
for (int j = 0; j < str.Length; j++)
{
if (str[j] == CheckBoxList1.Items[i].Value)
{
CheckBoxList1.Items[i].Selected = true;
}
}
}
萤火架构 2008-12-09
  • 打赏
  • 举报
回复
遍历CheckBoxList1中的ListItem
如楼上
ccimage 2008-12-09
  • 打赏
  • 举报
回复
遍历一遍不就Ok了吗。if(CheckBoxList1.Items[i].Value==xxx)CheckBoxList1.Items[i].Checked=True;

62,041

社区成员

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

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

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

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