Imports System.Data.SqlClient
Imports System.Data
Partial Class _Default
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
binddropdownlist_DataBinding(sender, e)
End If
End Sub
Protected Sub binddropdownlist_DataBinding(ByVal sender As Object, ByVal e As System.EventArgs) Handles binddropdownlist.DataBinding
Dim strCon As String
Dim strSelect As String
Dim con As SqlConnection
Dim sda As SqlDataAdapter
strCon = "Data Source=.;Initial Catalog=sheet;Integrated Security=True"
con = New SqlConnection(strCon)
strSelect = "select count(id) as id,areaBig from test group by areaBig"
sda = New SqlDataAdapter(strSelect, con)
Dim ds As New DataSet()
sda.Fill(ds, "test")
binddropdownlist.DataSource = ds
binddropdownlist.DataValueField = "id"
binddropdownlist.DataTextField = "areaBig"
binddropdownlist.DataBind()
End Sub
Protected Sub binddropdownlist_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles binddropdownlist.SelectedIndexChanged
Dim strCon As String
Dim con As SqlConnection
Dim strSelect As String
Dim sda As SqlDataAdapter
strCon = "Data Source=.;Initiial Catalog=sheet;Integrated Security=true"
con = New SqlConnection(strCon)
strSelect = "select id,areaSmall from test where areaBig='" + binddropdownlist.SelectedItem.Text + "'"
sda = New SqlDataAdapter(strSelect, con)
Dim ds As New DataSet()
sda.Fill(ds, "test")
DropDownList2.DataSource = ds
DropDownList2.DataValueField = "id"
DropDownList2.DataTextField = "areaSmall"
DropDownList2.DataBind()
End Sub
End Class