CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
(图)邪恶的韩国UMPC 使用 Java 编写数据库应用新规范
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  .NET技术 >  ASP.NET

DataList的EditItemTemplate中DropDownList的SelectedIndexChanged事件不响应问题

楼主oceanskytang(唐唐)2002-08-24 09:57:17 在 .NET技术 / ASP.NET 提问

<EditItemTemplate>  
      ......  
      <asp:DropDownList   id="Drop_zipcode2"   runat="server"   Height="22"   Width="103"     AutoPostBack="true"></asp:DropDownList>  
      <asp:TextBox   id="TB_areaname2"   runat="server"   Height="26"   Width="102"   ReadOnly="True"   Text=<%#Container.DataItem("区域名称")%>></asp:TextBox>  
        ......  
  </EditItemTemplate>  
   
  我在update_plantharvest.aspx.vb中这样定义了:  
   
  ......  
  Protected   WithEvents   Drop_zipcode2   As   System.Web.UI.WebControls.DropDownList  
  Protected   WithEvents   TB_areaname2   As   System.Web.UI.WebControls.TextBox  
  ......  
   
  Private   Sub   Drop_zipcode2_SelectedIndexChanged(ByVal   sender   As   System.Object,   ByVal   e   As   System.EventArgs)   Handles   Drop_zipcode2.SelectedIndexChanged  
                  Dim   TB_areaname2   As   TextBox  
                  TB_areaname2   =   CType(DL_plantharvest.FindControl("TB_areaname2"),   TextBox)  
                  Dim   SelString_Drop_zipcode2   As   String   =   "Select   区域名称   from   CD_QYFW   where   区域编码='"   &   Drop_zipcode2.SelectedItem.Text()   &   "'"  
                  Dim   connectStr_Drop_zipcode2   As   String   =   "Provider=MSDAORA;Password=wsj2002;User   ID=wsj;Data   Source=WsjOrcl"  
                  Dim   DbAdapter_Drop_zipcode2   As   OleDbDataAdapter   =   New   OleDbDataAdapter(SelString_Drop_zipcode2,   connectStr_Drop_zipcode2)  
                  Dim   MyDataSet_Drop_zipcode2   As   DataSet   =   New   DataSet()  
                  DbAdapter_Drop_zipcode2.Fill(MyDataSet_Drop_zipcode2,   "CD_QYFW")  
                  TB_areaname2.Text   =   MyDataSet_Drop_zipcode2.Tables("CD_QYFW").Rows(0).Item(0)  
          End   Sub  
   
  出现的问题是:  
  TB_areaname2中无响应,并不是如预期得到相对应与"区域编码"的"区域名称",该如何解决? 问题点数:20、回复次数:9Top

1 楼icyer()回复于 2002-08-24 10:33:06 得分 10

<asp:DropDownList   id="Drop_zipcode2"   runat="server"   Height="22"   Width="103"     AutoPostBack="true"   onSelectedIndexChanged="Drop_zipcode2_SelectedIndexChanged"></asp:DropDownList>  
  然后添加一个函数:  
  Protected   Sub   Drop_zipcode2_SelectedIndexChanged(ByVal   sender   As   System.Object,   ByVal   e   As   System.EventArgs)  
  ...  
  End   Sub  
  Top

2 楼oceanskytang(唐唐)回复于 2002-08-24 11:07:42 得分 0

出现了另外一个问题:  
   
  行   214:                 Dim   TB_areaname2   As   TextBox  
  行   215:                 TB_areaname2   =   CType(DL_plantharvest.FindControl("TB_areaname2"),   TextBox)  
  行   216:                 Dim   SelString_Drop_zipcode2   As   String   =   "Select   区域名称   from   CD_QYFW   where   区域编码='"   &   Drop_zipcode2.SelectedItem.Text()   &   "'"  
  行   217:                 Dim   connectStr_Drop_zipcode2   As   String   =   "Provider=MSDAORA;Password=wsj2002;User   ID=wsj;Data   Source=WsjOrcl"  
  行   218:                 Dim   DbAdapter_Drop_zipcode2   As   OleDbDataAdapter   =   New   OleDbDataAdapter(SelString_Drop_zipcode2,   connectStr_Drop_zipcode2)  
   
  异常详细信息:   System.NullReferenceException:   未将对象引用设置到对象的实例。  
  源文件:   c:\inetpub\wwwroot\AppleDB\update_plantharvest.aspx.vb         行:   216    
   
   
  我在第214行添加定义了Drop_zipcode2为DropDownList,还是出现了以上错误。  
  Dim   Drop_zipcode2   As   DropDownList  
  Drop_zipcode2   =   CType(DL_plantharvest.FindControl("Drop_zipcode2"),   DropDownList)  
  Top

3 楼linlimin()回复于 2002-08-24 11:43:25 得分 0

首先先邦定数据库到Drop_zipcode2:  
  Drop_zipcode2.DataSource=mydsBBS.Tables["UsersList"].DefaultView   ;  
  Drop_zipcode2.DataTextField=区域名称字段  
  Drop_zipcode2.DataValueField=区域编码  
  Drop_zipcode2.DataBind();  
  然后将Private   Sub   Drop_zipcode2_SelectedIndexChanged(ByVal   sender   As   System.Object,   ByVal   e   As   System.EventArgs)   Handles   Drop_zipcode2.SelectedIndexChanged  
                  Dim   TB_areaname2   As   TextBox  
                  TB_areaname2   =   CType(DL_plantharvest.FindControl("TB_areaname2"),   TextBox)  
                  Dim   SelString_Drop_zipcode2   As   String   =   "Select   区域名称   from   CD_QYFW   where   区域编码='"   &   Drop_zipcode2.SelectedItem.Text()   &   "'"  
                  Dim   connectStr_Drop_zipcode2   As   String   =   "Provider=MSDAORA;Password=wsj2002;User   ID=wsj;Data   Source=WsjOrcl"  
                  Dim   DbAdapter_Drop_zipcode2   As   OleDbDataAdapter   =   New   OleDbDataAdapter(SelString_Drop_zipcode2,   connectStr_Drop_zipcode2)  
                  Dim   MyDataSet_Drop_zipcode2   As   DataSet   =   New   DataSet()  
                  DbAdapter_Drop_zipcode2.Fill(MyDataSet_Drop_zipcode2,   "CD_QYFW")  
                  TB_areaname2.Text   =   MyDataSet_Drop_zipcode2.Tables("CD_QYFW").Rows(0).Item(0)  
          End   Sub  
  中的----   Dim   SelString_Drop_zipcode2   As   String   =   "Select   区域名称   from   CD_QYFW   where   区域编码='"   &   Drop_zipcode2.SelectedItem.Text()   &   "'"  
  改为-----   Dim   SelString_Drop_zipcode2   As   String   =   "Select   区域名称   from   CD_QYFW   where   区域编码='"   &   Drop_zipcode2.SelectedItem.Value()   &   "'"  
   
  Top

4 楼linlimin()回复于 2002-08-24 11:45:28 得分 0

试一下吧,我主要试用ASP.NET编写,至于VB.NET我不是很熟悉,见笑了!Top

5 楼monkey_zeng(未来报告)回复于 2002-08-24 11:57:13 得分 0

不执行事件,主要是因为AutoPostBack="true",设置为false时就不行.    
   
  因为对vb不熟,初步怀疑:  
  TB_areaname2   =   CType(DL_plantharvest.FindControl("TB_areaname2"),   TextBox)  
  出错.Top

6 楼icyer()回复于 2002-08-24 12:38:57 得分 0

Dim   Drop_zipcode2   As   DropDownList   =   CType(sender,   DropDownList)  
  Dim   cell   As   TableCell   =   CType(Drop_zipcode2.Parent,   TableCell)  
  Dim   TB_areaname2   As   TextBox   =   CType(cell.FindControl("TB_areaname2"),   TextBox)  
  Dim   SelString_Drop_zipcode2   As   String   =   "Select   区域名称   from   CD_QYFW   where   区域编码='"   &   Drop_zipcode2.SelectedItem.Text()   &   "'"  
  ...  
  Top

7 楼monkey_zeng(未来报告)回复于 2002-08-24 12:45:10 得分 0

还没有搞定呀,设置DropDownList的AutoPostBack属性为trueTop

8 楼oceanskytang(唐唐)回复于 2002-08-24 14:05:26 得分 0

Dim   cell   As   TableCell   =   CType(Drop_zipcode2.Parent,   TableCell)  
   
  这一行出错:System.InvalidCastException:   指定的转换无效。  
   
   
   
  我的头都大了,发现对DataList--EditItemTemplate中的控件进行SelectedIndexChanged,TextChanged操作,总报同一个错:  
  异常详细信息:   System.NullReferenceException:   未将对象引用设置到对象的实例。  
  不知该如何将它们定义?  
  还忘各位再出出主意!  
  Top

9 楼icyer()回复于 2002-08-24 14:44:30 得分 10

Dim   cell   As   DataListItem   =   CType(Drop_zipcode2.Parent,   DataListItem)Top

相关问题

  • 在datalist的EDITITEMTEMPLATE中使用Dropdownlist(使用的是代码分离)
  • 请问如何实现在DataList的<EditItemTemplate>模版内的DropDownList的数据绑定?
  • DropDownList的SelectedIndexChanged事件
  • 请问谁有从数据库填充DropDownList控件的例子, 这个DropDownList是要在DataList的EditItemTemplate中的,谢谢!
  • Datalist中EDITITEMTemplate的dropdwnlist 问题
  • dropdownlist的SelectedIndexChanged不响应?
  • 如何在datalist中使用dropdownlist?
  • ASP.NET DropDownList 如何使用SelectedIndexChanged事件?
  • datagrid <EditItemTemplate>里面绑定DropDownList的问题
  • 在DataList中如何使用DropDownList?

关键词

  • 区域
  • 编码
  • cell
  • zipcode2
  • areaname2
  • drop
  • plantharvest
  • selstring
  • selectedindexchanged
  • ctype

得分解答快速导航

  • 帖主:oceanskytang
  • icyer
  • icyer

相关链接

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

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
惹火投票。。火热进行中...

社区焦点:

教你怎样用C#搞笑整人
最懒惰的程序员写的Cache
程序员如何掌握专业英语
Java栈与堆
分享:让人懊恼的面试
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
北京创新乐知广告有限公司 版权所有, 京 ICP 证 070598 号
世纪乐知(北京)网络技术有限公司 提供技术支持
Copyright © 2000-2008, CSDN.NET, All Rights Reserved
GongshangLogo