ASP.NET 3.5将CheckBoxList中的多个选择存储到数据库 [英] ASP.NET 3.5 Store multiple selection from CheckBoxList to database
本文介绍了ASP.NET 3.5将CheckBoxList中的多个选择存储到数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我从网上获得的信息,应该放在哪里?还是有其他解决方案呢?请帮助我,非常感谢
This is what i get from online, where should i put in? or is it got any other solution to doing it? Please help me, Thanks a lot
Set:
string s = string.Empty;
foreach (ListItem itm in CheckBoxList1.Items)
{
if (itm.Selected)
{
s += itm.Value + "$";
}
}
Get:
string[] sl = s.Split("$");
foreach (string s in sl)
{
ListItem itm = CheckBoxList1.Items.FindByValue(s);
if (itm != null) itm.Selected = true;
}
推荐答案
"; } } 得到: 字符串 [] sl = s.Split("
"; } } Get: string[] sl = s.Split("
"); foreach (字符串 s in sl中的字符串) { ListItem itm = CheckBoxList1.Items.FindByValue(s); 如果(itm!= 空)itm.Selected = true ; }
"); foreach (string s in sl) { ListItem itm = CheckBoxList1.Items.FindByValue(s); if (itm != null) itm.Selected = true; }
将其作为属性放在代码的后面:
Put this as a property in your code behind:
public partial class WhateverYourClassNameIs
{
public String[] Selections //<-- change this to private if not being accessed to other classes.
{
get
{
string[] sl = s.Split("
这篇关于ASP.NET 3.5将CheckBoxList中的多个选择存储到数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文