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

被折叠的 条评论
为什么被折叠?



