关于dropdownlist控件的问题,语言=VB
在asp.net2.0中,有三个dropdownlist控件分别对应数据库里面的系部表(department),专业表(speciality)和班级表(class),现在在page_load事件中已经联结上了系部名称字段;代码如下:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim sql As String
Dim conn As New SqlConnection
conn.ConnectionString = "data source=192.168.31.199;initial catalog=kaoqin manager;user id=james5;password=james5; "
sql = "select * from department "
Dim cmd As New SqlCommand(sql, conn)
conn.Open()
Dim dr As SqlDataReader
dr = cmd.ExecuteReader()
DropDownList1.AppendDataBoundItems = True
DropDownList1.Items.Add(New ListItem( "--请选择-- ", "-1 "))
DropDownList1.DataSource = dr
DropDownList1.DataValueField = "departmentNo "
DropDownList1.DataTextField = "departmentname "
DropDownList1.DataBind()
End Sub
但是在dropdownload的Index_change事件中关联专业表是出了总是,老是自动刷新,而且每刷新一次,dropdownlist控件的系部和专业名称又会自动增加,请高手帮忙看一下错到哪里;不胜感激.关联字段如下:
Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
Dim sql As String
Dim conn As New SqlConnection
conn.ConnectionString = "data source=192.168.31.199;initial catalog=kaoqin manager;user id=james5;password=james5; "
sql = "select * from speciality where departmentNo= ' " & DropDownList1.SelectedValue & " ' "
Dim cmd As New SqlCommand(sql, conn)
conn.Open()
Dim dr As SqlDataReader
dr = cmd.ExecuteReader()
DropDownList5.AppendDataBoundItems = True