C#实现将选中复选框的信息返回给用户的方法


本文实例讲述了C#实现将选中复选框的信息返回给用户的方法。分享给大家供大家参考。具体实现方法如下:

/// <summary>
/// 自定义方法,获得复选框中选中的值,用指定的分隔符隔开
/// </summary>
/// <param name="split">分隔符</param>
/// <param name="chk">复选框名称</param>
/// <returns>返回复选框中选中的值</returns>
string GetCheckBoxItems(string split, params CheckBox[] chk)
{
string items = string.Empty;
for (int i = 0; i < chk.Length; i++)
{//将每一个选中的复选框的文本和分隔符累加到字符串中
if (chk[i].Checked)
{
items += chk[i].Text + split;
}
}
if (!string.IsNullOrEmpty(items))
{//如果有选中字符串,则将最后一个分隔符去掉
items = items.Substring(0, items.Length - 1);
}
return items;
}

希望本文所述对大家的C#程序设计有所帮助。


« 
» 
快速导航

Copyright © 2016 phpStudy | 豫ICP备2021030365号-3