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
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