<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

解决方案 »

  1.   

    出现了另外一个问题:行 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)
      

  2.   

    首先先邦定数据库到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() & "'"
      

  3.   

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

  4.   

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

  5.   

    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() & "'"
    ...
      

  6.   

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

  7.   

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

  8.   

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