best way to query on dropdownlist with another

D

DC Gringo

I have two dropdownlists where one is a set of districts and the other
sub-districts. Upon choosing a district in the first dropdownlist, I need
the relevant subdistricts to show in the second one.

Please help with code sample help with the following:

-----MY DROPDOWNLISTS------
<asp:dropdownlist id="Districts" runat="server"></asp:dropdownlist
<asp:dropdownlist id="SubDistricts" runat="server"></asp:dropdownlist>


-----MY RELEVANT CODE------

Protected _sqlStmt As String = _
"SELECT cols FROM tables"

Protected _sqlStmt3 As String = _
"SELECT tblDistrict.clnGUID, tblDistrict.clnName FROM tblDistrict ORDER
BY tblDistrict.clnName"

Protected _sqlStmt4 As String = _
"SELECT tblSubDistrict.clnGUID, tblSubDistrict.clnName FROM
tblSubDistrict ORDER BY tblSubDistrict.clnName"


Sub Page_Load(Source As Object, E As EventArgs)
If Not Page.IsPostBack Then
BindData()
End If
End Sub

Sub BindData()
Dim conString As String = "server=server;database=db;uid=user;pwd=pwd;"
Dim myDataSet1 As New DataSet
Dim myDataAdapter1 As New SqlDataAdapter(_sqlStmt, conString)
myDataAdapter1.Fill(myDataSet1, "CommunitiesT1")
DataGrid2.DataSource = myDataSet1.Tables("CommunitiesT1")


Dim myDataSet3 As New DataSet
Dim myDataAdapter3 As New SqlDataAdapter(_sqlStmt3, conString)
myDataAdapter3.Fill(myDataSet3, "DistrictsT")
Districts.DataSource = myDataSet3.Tables("DistrictsT")
Districts.DataMember = "DistrictsT"
Districts.DataTextField = "clnName"
Districts.DataValueField = "clnGUID"

Dim myDataSet4 As New DataSet
Dim myDataAdapter4 As New SqlDataAdapter(_sqlStmt4, conString)
myDataAdapter4.Fill(myDataSet4, "SubDistrictsT")
SubDistricts.DataSource = myDataSet4.Tables("SubDistrictsT")
SubDistricts.DataMember = "SubDistrictsT"
SubDistricts.DataTextField = "clnName"
SubDistricts.DataValueField = "clnGUID"


DataGrid2.DataBind()

Districts.DataBind()
Districts.Items.Insert(0,New ListItem("--ALL","0"))

SubDistricts.DataBind()
SubDistricts.Items.Insert(0,New ListItem("--ALL","0"))

End Sub
 
J

Jairo Nieto

I have a similar question. I have 2 dropdown lists, adn the information
needs to change on the second one, according to the user selection in the
first. I am currently using autopostback on the first dropdown list, so the
second one refreshes, but i need to achieve this without the autopostback,
how can i do it???
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top