当前位置:编程学习 > C#/ASP.NET >>

Listbox 多选 取的值 都一样~! 为什么

string strSQL = string.Format("insert into cusPermission(groupid,tel) values('{0}','", this.ListBox1.SelectedValue);
            for (int i = 0; i < ListBox2.Items.Count; i++)
            {
                if (ListBox2.Items[i].Selected)
                {

                    strSQL += "" + ListBox2.SelectedItem.Text + "";
                }
            }
            strSQL += "')";
            util.DBOper.DBOper.Insert2Table(strSQL);


红色那部分  是多选listbox,插入的时候数据库里面所存在的值都默认为0位置的listbox所选值,为什么,autopostback 设置了也没用 !

--------------------编程问答-------------------- 多选一般用CheckBoxList就行了吧。。。 --------------------编程问答--------------------
引用楼主 boboSuperman 的帖子:
                    strSQL += "" + ListBox2.SelectedItem.Text + ""; 
 


自己改。 --------------------编程问答-------------------- 你看看你在执行这个插入操作前是否有初始化ListBox2?跟踪一下看看。 --------------------编程问答--------------------
引用 2 楼 sp1234 的回复:
引用楼主 boboSuperman 的帖子:
strSQL += "" + ListBox2.SelectedItem.Text + "";


自己改。

赞细心 --------------------编程问答--------------------
引用 4 楼 sighforever 的回复:
引用 2 楼 sp1234 的回复:
引用楼主 boboSuperman 的帖子: 
strSQL += "" + ListBox2.SelectedItem.Text + ""; 


自己改。 
 
赞细心

"" --------------------编程问答-------------------- 帮忙顶一下,让了解的人来解答。 --------------------编程问答-------------------- ""之间少'~~? --------------------编程问答-------------------- 少什么 --------------------编程问答-------------------- 问题多半不在这段代码?
比如说在 IsPostBack之外执行了像这个控件添加数据或者其他操作?
补充:.NET技术 ,  ASP.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,