CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
IBM Rational 系统开发最佳实践工具包 WebSphere MQ 最佳实践 TOP 15
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  .NET技术 >  ASP.NET

listbox refresh如何实现?vb

楼主dh20156(风之石)2006-03-08 16:38:01 在 .NET技术 / ASP.NET 提问

listbox   refresh如何实现?language   =   vb  
  刚学.net,遇到这样一个问题,往一个listbox里添加listItem,但是添加进去了不能显示出来,需要再次添加数据的时候上一次添加进去的才显示出来。  
   
  搜索了MSDN和CSDN的相关资料,并没有发现能解决偶这个问题的比较清晰的答案,希望大家帮帮忙。如果要写类请将类的写法及页面中引用的方法告知,谢谢。 问题点数:100、回复次数:13Top

1 楼dh20156(风之石)回复于 2006-03-08 16:55:27 得分 0

麻烦各位兄弟姐妹关注一下,谢谢。Top

2 楼xcz1943(小钊)回复于 2006-03-08 16:57:32 得分 20

你怎么添加的,  
  public     sub   Page_load(byval   sender   as   object,....)  
        Addlist()  
  end   sub  
  public   sub   Addlist()  
        ......  
        '在这里添加你要添加的代码  
  end   subTop

3 楼dh20156(风之石)回复于 2006-03-08 17:07:12 得分 0

这是我添加东西的SUB,我是从一个hidden里取值给listbox2的,然后就发现只有在下一次添加的时候上一次添加的值才会在listbox2里显示出来。  
   
  Sub   ShowThis(send   as   object,e   as   eventArgs)  
  dim   sv   as   string  
  sv   =   listbox1.selectedItem.value  
   
  dim   scriptstr   as   string  
  scriptstr   =   "<script>"  
  scriptstr   =   scriptstr   +   "wPopup   =   window.open('about:blank','','width=300,height=180,left=200,top=200,menubar=no,resizeable=no,scrollbars=no,toolbar=no');"  
  scriptstr   =   scriptstr   +   "var   wPopupDoc=wPopup.document;"  
  scriptstr   =   scriptstr   +   "wPopupDoc.open();"  
  scriptstr   =   scriptstr   +   "wPopupDoc.write('<html><head></head><body   style=""border:none;background:buttonface;""   oncontextmenu=""return   false"">');"  
  scriptstr   =   scriptstr   +   "wPopupDoc.write('<table   width=""100%""   height=""100%""><tr   height=""30""><td><h4   id=""colname"">"   +   sv   +   "</h4></td></tr>');"  
  scriptstr   =   scriptstr   +   "wPopupDoc.write('<tr   height=""30""><td><b>=</b>   <input   type=""text""   name=""colval"">   </td></tr>');"  
  scriptstr   =   scriptstr   +   "wPopupDoc.write('<tr><td   align=""right""><input   type=""button""   value=""   Submit   ""   onclick=""window.opener.showcolval();"">   <input   type=""button""   value=""   Close   ""   onclick=""window.close();""></td></tr></table>');"  
  scriptstr   =   scriptstr   +   "wPopupDoc.write('</body></html>');"  
  scriptstr   =   scriptstr   +   "wPopupDoc.close();"  
  scriptstr   =   scriptstr   +   "<"+"/script>"  
   
  Response.Write(scriptstr)  
   
  If   hidetextbox1.value<>""   then  
  listbox2.items.add(new   listItem(hidetextbox1.value))  
  'listbox2.Refresh()  
   
  hidetextbox1.value   =   ""  
  End   if  
   
  End   SubTop

4 楼quanke1981(笨猪先跑)回复于 2006-03-08 17:26:40 得分 0

你的SUB是在什么时候调用的?Top

5 楼dh20156(风之石)回复于 2006-03-08 18:18:00 得分 0

这个Sub   ShowThis   是在listbox1选择后然后点击一个按钮时调用的。Top

6 楼dh20156(风之石)回复于 2006-03-08 18:58:27 得分 0

各位帮帮忙吧,谢谢!只要告诉我listbox如何才能调用Refresh()方法就好了,非常感谢!Top

7 楼cat_hsfz(我的新Blog在http://cathsfz.cnblogs.com)回复于 2006-03-08 19:19:35 得分 20

这个不是刷新问题,而可能是事件调用顺序问题。  
   
  ShowThis是某个按钮Click事件的直接执行过程吗?还是这个ShowThis的执行已经晚了(相对于Page的生命周期来说),所以添加的东西没有Render进去?最好贴出ShowThis被调用的调用链。Top

8 楼goody9807(http://goody9807.cnblogs.com)回复于 2006-03-08 19:34:03 得分 20

你Page_Load中如何写的  
  把的代码贴出来   
  有事联系  
  http://cnblogs.com/goody9807Top

9 楼dh20156(风之石)回复于 2006-03-08 20:36:49 得分 0

这是全文代码,用的是Northwind的Products表:  
  <%@   Language="VB"   Debug="True"   ValidateRequest="False"   EnableEventValidation="false"   %>  
  <html>  
  <head>  
  <title>test3.aspx</title>  
  <style>  
  body   {background:buttonface;font-size:12px;}  
  td   {font-size:12px;}  
  th   {font-size:12px;}  
  input   {font-size:12px;border:1px   solid   white;}  
  </style>  
  <script>  
  function   showcolval(){  
  var   wPopupElements   =   wPopup.document.all;  
  var   colname   =   wPopupElements.colname.innerText;  
  var   colvalue   =   wPopupElements.colval.value;  
  var   cs   =   colname   +   "="   +   colvalue;  
  document.all.hidetextbox1.value   =   cs;  
  wPopup.close();  
  }  
  </script>  
  </head>  
  <script   language="VB"   runat="server">  
   
  Sub   ShowThis(send   as   object,e   as   eventArgs)  
  If   listbox1.selectedIndex   >=   0   then  
  dim   sv   as   string  
  sv   =   listbox1.selectedItem.value  
   
  dim   scriptstr   as   string  
  scriptstr   =   "<script>"  
  scriptstr   =   scriptstr   +   "wPopup   =   window.open('about:blank','','width=300,height=180,left=200,top=200,menubar=no,resizeable=no,scrollbars=no,toolbar=no');"  
  scriptstr   =   scriptstr   +   "var   wPopupDoc=wPopup.document;"  
  scriptstr   =   scriptstr   +   "wPopupDoc.open();"  
  scriptstr   =   scriptstr   +   "wPopupDoc.write('<html><head></head><body   style=""border:none;background:buttonface;""   oncontextmenu=""return   false"">');"  
  scriptstr   =   scriptstr   +   "wPopupDoc.write('<table   width=""100%""   height=""100%""><tr   height=""30""><td><h4   id=""colname"">"   +   sv   +   "</h4></td></tr>');"  
  scriptstr   =   scriptstr   +   "wPopupDoc.write('<tr   height=""30""><td><b>=</b>   <input   type=""text""   name=""colval"">   </td></tr>');"  
  scriptstr   =   scriptstr   +   "wPopupDoc.write('<tr><td   align=""right""><input   type=""button""   value=""   Submit   ""   onclick=""window.opener.showcolval();"">   <input   type=""button""   value=""   Close   ""   onclick=""window.close();""></td></tr></table>');"  
  scriptstr   =   scriptstr   +   "wPopupDoc.write('</body></html>');"  
  scriptstr   =   scriptstr   +   "wPopupDoc.close();"  
  scriptstr   =   scriptstr   +   "<"+"/script>"  
   
  Response.Write(scriptstr)  
  End   if  
   
  If   hidetextbox1.value<>""   then  
  listbox2.items.add(new   listItem(hidetextbox1.value))  
  'listbox2.Refresh()  
   
  hidetextbox1.value   =   ""  
  End   if  
   
  End   Sub  
  Sub   ClearLayer(send   as   object,e   as   eventArgs)  
  If   listbox2.selectedIndex   >=   0   then  
  listbox2.items.remove(listbox2.selectedItem.value)  
  End   if  
  End   Sub  
   
  </script>  
  <body>  
  <center>  
  <form   name="form1"   method="post"   action="test3.aspx"   runat="server">  
  <fieldset>  
  <legend>Filter   by   queryString</legend>  
  <asp:GridView   id="GridView1"   DataSourceID="SqlDataSource1"   AllowPaging="True"   PageSize="20"   AllowSorting="True"   AutoGenerateColumns="True"   runat="server"/>  
  <asp:SqlDataSource   id="SqlDataSource1"   SelectCommand="Select   Top   100   *   From   [Products]   Where   ([ProductID]   =   @ProductID)   OR   ([ProductName]   Like   '%'   +   @ProductName   +   '%')   OR   ([SupplierID]   =   @SupplierID)   OR   ([CategoryID]   =   @CategoryID)   OR   ([QuantityPerUnit]   Like   '%'   +   @QuantityPerUnit   +   '%')   OR   ([UnitPrice]   <=   CONVERT(Money,@UnitPrice))   OR   ([UnitsInStock]   <=   CONVERT(int,@UnitsInStock))   OR   ([UnitsOnOrder]   <=   CONVERT(int,@UnitsOnOrder))   OR   ([ReorderLevel]   <=   CONVERT(int,@ReorderLevel))"   ConnectionString="<%$   ConnectionStrings:Northwind   %>"   runat="server">  
  <SelectParameters>  
  <asp:QueryStringParameter   Name="ProductID"   QueryStringField="ProductID"   DefaultValue="0"   />  
  <asp:QueryStringParameter   Name="ProductName"   QueryStringField="ProductName"   DefaultValue="\"   />  
  <asp:QueryStringParameter   Name="SupplierID"   QueryStringField="SupplierID"   DefaultValue="0"   />  
  <asp:QueryStringParameter   Name="CategoryID"   QueryStringField="CategoryID"   DefaultValue="0"   />  
  <asp:QueryStringParameter   Name="QuantityPerUnit"   QueryStringField="QuantityPerUnit"   DefaultValue="\"   />  
  <asp:QueryStringParameter   Name="UnitPrice"   QueryStringField="UnitPrice"   DefaultValue="-1"   />  
  <asp:QueryStringParameter   Name="UnitsInStock"   QueryStringField="UnitsInStock"   DefaultValue="-1"   />  
  <asp:QueryStringParameter   Name="UnitsOnOrder"   QueryStringField="UnitsOnOrder"   DefaultValue="-1"   />  
  <asp:QueryStringParameter   Name="ReorderLevel"   QueryStringField="ReorderLevel"   DefaultValue="-1"   />  
  </SelectParameters>  
  </asp:SqlDataSource>  
   
  <asp:SqlDataSource   id="SqlDataSource2"   SelectCommand="Select   Top   100   *   From   [Products]   Where   ([ProductID]   =   @ProductID)   OR   ([ProductName]   Like   '%'   +   @ProductName   +   '%')   OR   ([SupplierID]   =   @SupplierID)   OR   ([CategoryID]   =   @CategoryID)   OR   ([QuantityPerUnit]   Like   '%'   +   @QuantityPerUnit   +   '%')   OR   ([UnitPrice]   >=   CONVERT(Money,@UnitPrice))   OR   ([UnitsInStock]   >=   CONVERT(int,@UnitsInStock))   OR   ([UnitsOnOrder]   >=   CONVERT(int,@UnitsOnOrder))   OR   ([ReorderLevel]   >=   CONVERT(int,@ReorderLevel))"   ConnectionString="<%$   ConnectionStrings:Northwind   %>"   runat="server">  
  <SelectParameters>  
  <asp:QueryStringParameter   Name="ProductID"   QueryStringField="ProductID"   DefaultValue="0"   />  
  <asp:QueryStringParameter   Name="ProductName"   QueryStringField="ProductName"   DefaultValue="\"   />  
  <asp:QueryStringParameter   Name="SupplierID"   QueryStringField="SupplierID"   DefaultValue="0"   />  
  <asp:QueryStringParameter   Name="CategoryID"   QueryStringField="CategoryID"   DefaultValue="0"   />  
  <asp:QueryStringParameter   Name="QuantityPerUnit"   QueryStringField="QuantityPerUnit"   DefaultValue="\"   />  
  <asp:QueryStringParameter   Name="UnitPrice"   QueryStringField="UnitPrice"   DefaultValue="10000000"   />  
  <asp:QueryStringParameter   Name="UnitsInStock"   QueryStringField="UnitsInStock"   DefaultValue="10000000"   />  
  <asp:QueryStringParameter   Name="UnitsOnOrder"   QueryStringField="UnitsOnOrder"   DefaultValue="10000000"   />  
  <asp:QueryStringParameter   Name="ReorderLevel"   QueryStringField="ReorderLevel"   DefaultValue="10000000"   />  
  </SelectParameters>  
  </asp:SqlDataSource>  
  </fieldset>  
   
  <fieldset>  
  <legend>Filter   by   formPost</legend>  
  <table>  
  <tr>  
  <td>  
  <asp:label   id="listLabel1"   associatedControlID="listbox1"   text="Select   The   Columns:"   font-bold="true"   runat="server"/>  
  <br>  
  <asp:listbox   id="listbox1"   DataSourceID="SqlDataSource3"   DataTextField="name"   width="200px"   height="150px"   runat="server"/>  
  <asp:SqlDataSource   id="SqlDataSource3"   SelectCommand="Select   [name]   From   [syscolumns]   Where   [id]   =   object_id(N'[Products]')   And   [name]   <>   'Discontinued'"   ConnectionString="<%$   ConnectionStrings:Northwind   %>"   runat="server"   />  
  <br>  
  <asp:button   id="selectColumn"   onclick="ShowThis"   text=">>"   runat="server"/>  
  <input   type="hidden"   id="hidetextbox1"   runat="server"/>  
  </td>  
  <td>  
  <asp:label   id="listLabel2"   associatedControlID="listbox2"   text="Selected   Columns:"   font-bold="true"   runat="server"/>  
  <br>  
  <asp:listbox   id="listbox2"   DataTextField="name"   width="200px"   height="150px"   runat="server"/>  
  <br>  
  <asp:button   id="clearColumn"   text="<<"   onclick="ClearLayer"   runat="server"/>  
  </td>  
  </tr>  
  </fieldset>  
  </form>  
  </center>  
   
  </body>  
  </html>Top

10 楼dh20156(风之石)回复于 2006-03-09 14:04:01 得分 0

各位帮帮忙吧,谢了。Top

11 楼nameone(过客)回复于 2006-03-09 14:25:59 得分 20

UPTop

12 楼cuike519(I will be back!)回复于 2006-03-10 09:56:51 得分 20

如果你在Page_Load里面有类似下面的代码:  
  if(!IsPostBack){  
  //   bind   listbox  
  }  
  那么你在向ListBox中添加内容後,需要重新绑定数据(再次调用bind   listbox的代码),才能体现你的结果。Top

13 楼dh20156(风之石)回复于 2006-03-10 11:14:47 得分 0

TO:cuike519(I   will   be   back!)    
  偶新学,能否再讲解详细点?或者有什么手册介绍偶下载看看,非常感谢。Top

相关问题

  • vb的listbox列表框能不能实现多行现实?
  • 请各位高手帮小女看看,在vb中,listbox如何实现item的上下移动,谢谢!!!!
  • 如何使用vb实现利用按钮对ListBox中的条目进行添加和删除?
  • ListBox如何实现换行?
  • 用vb可以实现吗?
  • 用vb实现pv操作
  • 用VB的ADO实现
  • 用VB的ADO实现
  • 怎样用vb实现skin?
  • VB中实现BASE64加密

关键词

  • scriptstr
  • wpopupdoc
  • write

得分解答快速导航

  • 帖主:dh20156
  • xcz1943
  • cat_hsfz
  • goody9807
  • nameone
  • cuike519

相关链接

  • CSDN .NET频道
  • .NET类图书
  • C#类图书
  • .NET类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
北京创新乐知广告有限公司 版权所有, 京 ICP 证 070598 号
世纪乐知(北京)网络技术有限公司 提供技术支持
Copyright © 2000-2008, CSDN.NET, All Rights Reserved
GongshangLogo