CheckBoxList 获取选择的内容和根据内容判断是否选择

本文详细解析了一段使用C#编写的代码片段,展示了如何通过循环遍历组合值并进行字符串操作,实现选择判断功能。包括获取用户选择的值、拼接成字符串以及根据给定的条件进行选择项的选中状态设置。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

//获得选择的Value值

string topupway = string.Empty;
for (int i = 0; i < cblTopUpWay.Items.Count; i++)
{
if (cblTopUpWay.Items[i].Selected)
{
topupway += cblTopUpWay.Items[i].Value+"|";//这里也可以用逗号(,)
}
}
Response.Write(string.Format("<script>alert('{0}')</script>",topupway));


//根据值选择的进行判断是否选择

string way = "net|168|mobile|mobilecard|card|other|";
string checkvalue = string.Empty;
string[] topupway =way.Split('|');
for (int i = 0; i < cblTopUpWay.Items.Count; i++)
{
checkvalue = cblTopUpWay.Items[i].Value;
if (Array.IndexOf<string>(topupway, checkvalue) != -1)
{
cblTopUpWay.Items[i].Selected = true;
}
else
{
cblTopUpWay.Items[i].Selected = false;
}
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值