listbox添加的问题?

问题描述

有3个listboxlistbox1listbox2listbox3listbox1是省的信息listbox2是对应市的信息现在前面2个联动好用但是我想点button实现把listbox2的值添到listbox3中加了如下代码不好用只添加第一个省的市的信息请高手指点下应该怎么做才实现选完省信息对应的市添到listbox3中呢PrivateSubbtn_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)Handlesbtn.ClickDimiAsIntegerFori=0To(Me.listbox2.Items.Count)-1IfMe.listbox2.Items(i).Selected=TrueThenIfMe.Listbox3.Items.Contains(Me.listbox2.Items(i))=FalseThenListbox3.Items.Add(Me.listbox2.Items(i))EndIfEndIfNextiEndSub

解决方案

解决方案二:
循环倒着写看看PrivateSubbtn_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)Handlesbtn.ClickDimiAsIntegerFori=Me.listbox2.Items.Count-1To0Step-1IfMe.listbox2.Items(i).Selected=TrueThenIfMe.Listbox3.Items.Contains(Me.listbox2.Items(i))=FalseThenListbox3.Items.Add(Me.listbox2.Items(i))EndIfEndIfNextiEndSub
解决方案三:
LS的不好用哦。为什么我选listbox1里的值点击buttonlistbox2都是默认显示listbox1是1的值?
解决方案四:
你的联动有问题,发代码上来看.
解决方案五:
哦联动是着样的也是在网上找的'建立数据库连接DimconnAsSqlConnection=NewSqlConnection(ConfigurationSettings.AppSettings("connectionString"))'如果设置了web.config,也可以从web.config中读取数据库连接字符串conn.Open()DimcmdAsSqlCommand=NewSqlCommandcmd.Connection=conn'====================================================================================='生成客户端脚本控制的联动菜单'查询Tb_Province表获得所有的省份DimsqlstrAsString="SELECTzhuid,zhunameFROMzhulmorderbyzhuid"cmd.CommandText=sqlstrDimsqldaAsSqlDataAdapter=NewSqlDataAdapter(cmd)'建立临时表存储省份数据DimProvinceAsDataTable=NewDataTablesqlda.Fill(Province)'Response.Write("将省份数据绑定到DropDownList1控件")'Response.End()'将省份数据绑定到DropDownList1控件listbox1.DataSource=Provincelistbox1.DataValueField="zhuid"listbox1.DataTextField="zhuname"IfNotIsPostBackThenlistbox1.DataBind()'获取省份的个数DimProvinceNumAsInteger=Province.Rows.Count()'使用StringBuilder构造含客户端控制脚本的字符串DimsbscriptAsNewSystem.Text.StringBuildersbscript.Append("<script><!--")sbscript.Append(Environment.NewLine&"vargroup=newArray("&ProvinceNum&");"&Environment.NewLine&"for(i=0;i<"&ProvinceNum&";i++){group[i]=newArray()}"&Environment.NewLine)'循环从省份临时表中取出一个省份,然后在数据库中查询此省份下的城市DimiAsIntegerDimjAsIntegerDimtempclassAsDataTableDimCityNumAsIntegerFori=0ToProvinceNum-1sqlstr="SELECTfuid,funameFROMfulmWHERELeft(zhuid,2)='"&Province.Rows(i)(0)&"'orderbyfuid"cmd.CommandText=sqlstrsqlda=NewSqlDataAdapter(cmd)tempclass=NewDataTablesqlda.Fill(tempclass)CityNum=tempclass.Rows.Count()'Response.Write("省份:"&Province.Rows(i)(0)&"有市"&CityNum&"个<br>")'将读取到的城市数据放入客户端脚本中Forj=0ToCityNum-1sbscript.Append("group["&i&"]["&j&"]=newOption("""&tempclass.Rows(j)(1)&""","""&tempclass.Rows(j)(0)&""");"&Environment.NewLine)NextNext'加入客户端脚本控制代码sbscript.Append(Environment.NewLine&"functionRedirect(x){"&Environment.NewLine&"for(m=Form1.listbox2.options.length-1;m>0;m--){Form1.listbox2.options[m]=null}")sbscript.Append(Environment.NewLine&"if(group[x].length==0){")sbscript.Append(Environment.NewLine&"Form1.listbox2.options[0]=newOption('---请选择---','无')}")sbscript.Append(Environment.NewLine&"for(i=0;i<group[x].length;i++){"&Environment.NewLine&"Form1.listbox2.options[i]=newOption(group[x][i].text,group[x][i].value)}")sbscript.Append(Environment.NewLine&"Form1.listbox2.options[0].selected=true;Form1.classid.value=Form1.listbox2.options[0].value;}")sbscript.Append(Environment.NewLine&"functionchoose(x){Form1.classid.value=Form1.listbox2.options[x].value;}")sbscript.Append(Environment.NewLine&"-->")sbscript.Append("<")sbscript.Append("/")sbscript.Append("script>")'注册客户端脚本,将脚本内容写入客户端输出流DimstrscriptAsString=sbscript.ToString()If(NotIsClientScriptBlockRegistered("clientScript"))ThenRegisterClientScriptBlock("clientScript",strscript)EndIf'====================================================================================='初始化DropDownList2中的内容sqlstr="SELECTfuid,funameFROMfulmWHERE(Left(zhuid,2)='"&Province.Rows(0)(0)&"')"cmd.CommandText=sqlstrsqlda=NewSqlDataAdapter(cmd)DimdtCityAsDataTable=NewDataTablesqlda.Fill(dtCity)listbox2.DataSource=dtCitylistbox2.DataValueField="fuid"listbox2.DataTextField="funame"IfNotIsPostBackThenlistbox2.DataBind()sqlda.Dispose()cmd.Dispose()conn.Close()
解决方案六:
你是用的客户端的连动,不能保存listbox2的状态.所以出现这种情况,简单的做法是在服务器端连动,将listbox1的autopostback设为true,在selectedindexchanged事件中联动,这样才能保存状态,否则用上面的方法还要在Page_load中重新根据listbox1的选项再生成listbox2的选项,然后根据Request.Form["listobx2的值来设置listbox2的选中的项.
解决方案七:
直接绑定的话把值取出来然后赋值给list3
解决方案八:
selectedindexchanged是什么事件没用过
解决方案九:
大哥们详细给讲讲把不会写
解决方案十:
selectedindexchanged就是选择listbox1时触发的服务器事件,将litbox1设成autopostback="true"就会触发这个事件。
解决方案十一:
HTML代码:<asp:ListboxID="Listbox1"runat="server"OnSelectedIndexChanged="Listbox1_SelectedIndexChanged"AutoPostBack="True">CS代码:protectedvoidListbox1_SelectedIndexChanged(objectsender,EventArgse){这里根据listbox1的selectedvalue来绑定listbox2}
解决方案十二:
引用10楼cpp2017的回复:

HTML代码:<asp:ListboxID="Listbox1"runat="server"OnSelectedIndexChanged="Listbox1_SelectedIndexChanged"AutoPostBack="True">CS代码:protectedvoidListbox1_SelectedIndexChanged(objectsender,EventArgse){这里根据listbox1的selectedvalue来绑定listbox2}

要是着样联动的话就不用我上面的代码了把?怎么联动。。。
解决方案十三:
不用上面的代码了。怎么联动?查数据库,绑定listbox2条件就是省=listbox1的选中的值,这里应该是单选吧?考虑用dropdownlsit
解决方案十四:
不知道要怎么写
解决方案十五:
谁会给个例子什么的可以么不知道应该怎么做
解决方案:
好久了大家帮帮忙把

时间: 2024-09-16 03:16:17

listbox添加的问题?的相关文章

给ListBox添加双击事件示例代码_javascript技巧

复制代码 代码如下: <!--创建一个JS调用button的click事件--> <script type="text/javascript"> function JsListChangeItem() { document.getElementById("buttonShow").click(); } </script> <!--创建一个隐藏的button,创建双击事件---> <asp:Button ID=&q

listbox添加选中项??

问题描述 两个listbox怎么把listbox1的所有选中项都添到listbox2中啊??? 解决方案 解决方案二:for(inti=0;i<L1.Items.Count;i++){if(L1.Items[i].Selected){L2.Items.Add(L1.Items[i]);L1.Items.Remove(L1.Items[i]);i--;} 解决方案三:foreach(objectlinlistBox1.SelectedItems){listBox2.Items.Add(l);}解决

对ListBox的添加移除操作实例分享_实用技巧

前台代码: 复制代码 代码如下: <div> <asp:ListBox ID="ListBox1" runat="server" Height="123px" Width="113px" SelectionMode="Multiple"> <asp:ListItem>tom</asp:ListItem> <asp:ListItem>jion<

ListBox控件添加数据慢

问题描述 winform开发,用listbox控件添加4000多条数据时,加载界面速度比较慢,要一次性加载,如何解决?目前是用for循环一条条添加,如:for(inti=0;i<4000;i++){ListBox1.Items.Add(XX);} 解决方案 本帖最后由 sven168 于 2015-09-05 20:27:43 编辑解决方案二:是否可以考虑通过线程加载listbox,这样不会导致主画面卡解决方案三:用virtualmodehttp://www.cnblogs.com/hcfala

ListBox编程两例

1. 为ListBox添加水平方向的滚动条 SendMessage (ListBox1->Handle,LB_SETHORIZONTALEXTENT,ListBox1->Width + 32,0) ; 2. 为Listbox添加图标 首先需要设置Listbox的Style属性为lbOwnerDrawVariable; const margin = 2 ; // Margin around each bitmap//----------------------------------------

背水一战 Windows 10 (33) - 控件(选择类): ListBox, RadioButton, CheckBox, ToggleSwitch

原文:背水一战 Windows 10 (33) - 控件(选择类): ListBox, RadioButton, CheckBox, ToggleSwitch [源码下载] 背水一战 Windows 10 (33) - 控件(选择类): ListBox, RadioButton, CheckBox, ToggleSwitch 作者:webabcd 介绍背水一战 Windows 10 之 控件(选择类) ListBox RadioButton CheckBox ToggleSwitch 示例1.L

Silverlight实用窍门系列:43.Silverlight从ListBox拖拽图标到另一ListBox【附带源码实例】

在本实例中我们将从ListBox中拖出一个图标到另外一个ListBox中,这是一个比较有用的小功能,在这里我们首先来看运行效果(点击下面的图片即可拖动左边的图标到右边的ListBox中去). 在线演示 实现过程是:1.我们把这个过程分为鼠标左键点击到左边的图标,使用Image_MouseLeftButtonDown事件.(设置一个标识符,标示当前已经被鼠标点击下去) 2.点击到这个图标不放,在整个Canvas内移动,使用LayoutRoot_MouseMove事件(此时设置一个图标跟随鼠标的位置

重新想象 Windows 8 Store Apps (5) - 控件之集合控件: ComboBox, ListBox, FlipView, ItemsControl, ItemsPresenter

原文:重新想象 Windows 8 Store Apps (5) - 控件之集合控件: ComboBox, ListBox, FlipView, ItemsControl, ItemsPresenter [源码下载] 重新想象 Windows 8 Store Apps (5) - 控件之集合控件: ComboBox, ListBox, FlipView, ItemsControl, ItemsPresenter 作者:webabcd 介绍重新想象 Windows 8 Store Apps 之集合

关于silverlight中如何更新(增删改)集合ItemsSource后更新到UI(Listbox、DataGrid等)

请看微软资料 http://msdn.microsoft.com/zh-cn/library/system.windows.controls.itemscontrol.itemssource%28v=vs.95%29.aspx   具体方案为:将ItermsSource设置为实现 INotifyCollectionChanged 接口的对象,以使集合的更改在 ItemsControl 中反映出来. ObservableCollection<T> 类即定义这样的对象,不要贪图方便而使用List&