CheckBoxList去分号绑定选中值
2015-08-20 16:51
281 查看
数据库表中的样式:
人;狗;猫;( 数据库对应字段名Text)
对应的value:1;2;3; (数据库中的字段名:itemValue)
前段checkboxlist的ID:checkbox
//初始化页面给CheckBoxList选中的复选框 赋值
for (int i = 0; i < itemValue.Value.Split(';').Length; i++)
{
for (int j = 0; j < checkbox.Items.Count; j++)
{
if (itemValue.Value.Split(';')[i] == CHB_FenLei.Items[j].Value)
{
checkbox.Items[j].Selected = true;
}
}
//复选框拼接后存入数据库为一个字段
string itemvalue="";
string text="";
for (int i = 0; i <
checkbox.Items.Count; i++)
{
if (checkbox.Items[i].Selected)
{
itemvalue+=
checkbox.Items[i].Value + ";";
text+= checkbox.Items[i].Text + ";";
}
}
或者: string m_strTemp = string.Empty;
for (int i = 0; i < CBoxListAnswer.Items.Count; i++)//读取CheckBoxList
选中的值,保存起来
{
if (CBoxListAnswer.Items[i].Selected)
{
m_strTemp += CBoxListAnswer.Items[i].Value + ",";
}
}
if (!string.IsNullOrEmpty(m_strTemp))
Label1.Text = m_strTemp.Substring(0, m_strTemp.Length - 1);
else
Label1.Text = m_strTemp;
人;狗;猫;( 数据库对应字段名Text)
对应的value:1;2;3; (数据库中的字段名:itemValue)
前段checkboxlist的ID:checkbox
//初始化页面给CheckBoxList选中的复选框 赋值
for (int i = 0; i < itemValue.Value.Split(';').Length; i++)
{
for (int j = 0; j < checkbox.Items.Count; j++)
{
if (itemValue.Value.Split(';')[i] == CHB_FenLei.Items[j].Value)
{
checkbox.Items[j].Selected = true;
}
}
//复选框拼接后存入数据库为一个字段
string itemvalue="";
string text="";
for (int i = 0; i <
checkbox.Items.Count; i++)
{
if (checkbox.Items[i].Selected)
{
itemvalue+=
checkbox.Items[i].Value + ";";
text+= checkbox.Items[i].Text + ";";
}
}
或者: string m_strTemp = string.Empty;
for (int i = 0; i < CBoxListAnswer.Items.Count; i++)//读取CheckBoxList
选中的值,保存起来
{
if (CBoxListAnswer.Items[i].Selected)
{
m_strTemp += CBoxListAnswer.Items[i].Value + ",";
}
}
if (!string.IsNullOrEmpty(m_strTemp))
Label1.Text = m_strTemp.Substring(0, m_strTemp.Length - 1);
else
Label1.Text = m_strTemp;
相关文章推荐
- Java学习--(十)final关键字
- HDU 4109 Instrction Arrangement拓扑排序 关键路径模板
- Mac 使用adb shell 命令
- SharePoint 2013 通过HttpModule 管理视图权限
- 磁盘管理
- iOS开发——多线程篇——快速生成沙盒目录的路径,多图片下载的原理、SDWebImage框架的简单介绍
- Service不完全解析
- 最小环
- oracle表分区详解
- android学习笔记 代码中隐藏标题栏
- 可下载全球历史卫星,无偏移、高精度-谷歌地球卫片
- 关于SearchView的一些小细节
- const
- HDU - 5396 Expression
- BZOJ1071
- QT学习之路之截图
- 三种方法实现js跨域访问
- jboss jms 实例
- 二叉树的层次遍历
- oracle常见报错总结