首页 新闻 会员 周边

asp.net Listbox控件同时选中多个值,怎样循环插入数据库中

0
悬赏园豆:100 [待解决问题]

第一个listbox里面有值“张三、里斯、王五”
第二个listbox里面有值“字段1,字段2,字段3”
第三个listbox里面有值“权限1,权限2,权限3”

我想在数据库中以这种形式插入值

张三 字段1 权限1
张三 字段1 权限2
张三 字段2 权限3

里斯同上
该怎么做

一直在冬眠的主页 一直在冬眠 | 初学一级 | 园豆:0
提问于:2011-06-16 16:51
< >
分享
所有回答(4)
0

遍历listBox里面的数据

for()

 

{

}

宫恒满 | 园豆:210 (菜鸟二级) | 2011-06-16 17:32
为毛要循环?
支持(0) 反对(0) JCdon | 园豆:2 (初学一级) | 2011-06-16 17:33
0

应该不难吧  得到listbox 的选择值 分别赋值 三个对应的字段 插入数据就OK了

JCdon | 园豆:2 (初学一级) | 2011-06-16 17:33
0

int  peopleCount = 第一个ListBox的ID.Items.Count;

int relativeCount = peopleCount;

string[] ziduan = new string[peopleCount];

string[] quanxian = new string[peopleCount];

string peopleName = "";

for(int iName =0;iName = peopleCount;iName ++)

{

  peopleName = 第一个ListBox的ID.Items[iName].Value;

  for(int iRelativeCount= 0;iRelativeCount < relativeCount;iRelativeCount++)

    {

        ziduan[iRelativeCount] = 第二个ListBox的ID.Items[iRelativeCount].Value;

        quanxian[iRelativeCount] = 第三个ListBox的ID.Items[iRelativeCount].Value;

    }

 

   插入吧 参数是  peopleName ziduan quanxian

}

 

 

希望能帮到你!

天添 | 园豆:178 (初学一级) | 2011-06-16 17:38
0

foreach不是蛮好用的么。

webaspx | 园豆:1973 (小虾三级) | 2011-06-21 12:36
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册