设置或者得到CheckBoxList选中了的值

#region 设置或者得到CheckBoxList选中了的值
ExpandedSubBlockStart.gifContractedSubBlock.gif       
/**//// <summary>
InBlock.gif       
/// 初始化CheckBoxList中哪些是选中了的 InBlock.gif        /// </summary>
InBlock.gif       
/// <param name="checkList">CheckBoxList</param>
InBlock.gif       
/// <param name="selval">选中了的值串例如:"0,1,1,2,1"</param>
ExpandedSubBlockEnd.gif       
/// <param name="separator">值串中使用的分割符例如"0,1,1,2,1"中的逗号</param>

InBlock.gif        public static string SetChecked(CheckBoxList checkList,string selval,string separator)
ExpandedSubBlockStart.gifContractedSubBlock.gif       
...{
InBlock.gif            selval
= separator + selval + separator;        //例如:"0,1,1,2,1"->",0,1,1,2,1,"
InBlock.gif
            for(int i=0; i<checkList.Items.Count; i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif           
...{
InBlock.gif                checkList.Items[i].Selected
= false;
InBlock.gif               
string val = separator + checkList.Items[i].Value + separator;
InBlock.gif               
if(selval.IndexOf(val)!=-1)
ExpandedSubBlockStart.gifContractedSubBlock.gif               
...{
InBlock.gif                    checkList.Items[i].Selected
= true;
InBlock.gif                    selval
= selval.Replace(val,separator);        //然后从原来的值串中删除已经选中了的
InBlock.gif
                    if(selval == separator)        //selval的最后一项也被选中的话,此时经过Replace后,只会剩下一个分隔符
ExpandedSubBlockStart.gifContractedSubBlock.gif
                    ...{       
InBlock.gif                        selval
+= separator;        //添加一个分隔符
ExpandedSubBlockEnd.gif
                    }

ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

InBlock.gif            selval
= selval.Substring(1,selval.Length-2);        //除去前后加的分割符号
InBlock.gif
            return selval;
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif       
/**//// <summary>
InBlock.gif       
/// 得到CheckBoxList中选中了的值
InBlock.gif       
/// </summary>
InBlock.gif       
/// <param name="checkList">CheckBoxList</param>
InBlock.gif       
/// <param name="separator">分割符号</param>
ExpandedSubBlockEnd.gif       
/// <returns></returns>

InBlock.gif        public static string GetChecked(CheckBoxList checkList, string separator)
ExpandedSubBlockStart.gifContractedSubBlock.gif       
...{
InBlock.gif           
string selval = "";
InBlock.gif           
for(int i=0;i<checkList.Items.Count;i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif           
...{
InBlock.gif               
if(checkList.Items[i].Selected)
ExpandedSubBlockStart.gifContractedSubBlock.gif               
...{
InBlock.gif                    selval
+= checkList.Items[i].Value + separator;
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

InBlock.gif           
return selval;
ExpandedSubBlockEnd.gif        }

ExpandedBlockEnd.gif       
#endregion

转载于:https://www.cnblogs.com/pbwf/archive/2007/05/26/761101.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值