473,503 Members | 11,237 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

best way to query on dropdownlist with another

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

--
_____
DC G
Nov 18 '05 #1
2 1202
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???

"DC Gringo" <dc******@visiontechnology.net> wrote in message
news:uN**************@TK2MSFTNGP11.phx.gbl...
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

--
_____
DC G

Nov 18 '05 #2
Check out my free ListLink control.
http://www.metabuilders.com/tools/ListLink.aspx

__
Andy Smith

"Jairo Nieto" <ja***@axesnet.com> wrote in message
news:#3**************@tk2msftngp13.phx.gbl...
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???

"DC Gringo" <dc******@visiontechnology.net> wrote in message
news:uN**************@TK2MSFTNGP11.phx.gbl...
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

--
_____
DC G


Nov 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2351
by: Newbie | last post by:
I have a C# asp.net webform that contains a dropdownlist and a button that allows the user to select another item in the dropdownlist. The webform should work as follows: When the user selects...
2
1484
by: John Bonds | last post by:
I have made a Template column in my DataGrid that contains a DropDownList. My main SQL query that is bound to this datagrid joins with another table in the following way: SELECT * FROM Customer...
3
1205
by: Rob Venable | last post by:
Hi everyone, Can anyone see a problem with this code. I'm kinda new to asp.net and I'm having a problem populating a drop down list with a database query. The results of my query populate the list...
10
5284
by: Sacha Korell | last post by:
I'm trying to load a drop-down list with all DropDownList control names from another page. How would I be able to find those DropDownList controls? The FindControl method will only find a...
0
1062
by: Kimberly Walker | last post by:
Im farily new to the .Net so please bear with me. I have several dropdownlist that is bound to a sql string. For example dim sqlstring as string="Select books from SuborgT where books=New" I...
4
1634
by: Dave | last post by:
(My apologies for posting this on two forums. I have just found out the other one was the incorrect location) I am writing a VB.NET 2003 web application to operate on my company's intranet. It...
1
4636
by: MaryamSh | last post by:
Hi, I am creating a Dynamic Search in my application. I create a user control and in Page_load event I create a dynamic dropdownlist and 2 dynamic button (Add,Remove) By pressing Add button...
0
3466
by: MaryamSh | last post by:
Create Dynamic Dropdownlist Controls and related event -------------------------------------------------------------------------------- Hi, I am creating a Dynamic Search in my application. I...
2
1612
by: rajendrsedhain | last post by:
Hi, I have 1 checkboxlist, 5 dropdownlits and three textboxes.I have to write the SQL query and c# code for that advanced search. <asp:CheckBoxList ID="reposotoryCheckBoxList" runat="server"...
0
7194
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7267
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7316
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6976
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7449
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5566
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3148
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
729
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
372
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.