best way to query on dropdownlist with another

Discussion in 'ASP .Net Web Controls' started by DC Gringo, Mar 4, 2004.

  1. DC Gringo

    DC Gringo Guest

    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
     
    DC Gringo, Mar 4, 2004
    #1
    1. Advertising

  2. DC Gringo

    Jairo Nieto Guest

    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" <> wrote in message
    news:...
    > 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
    >
    >
     
    Jairo Nieto, Mar 5, 2004
    #2
    1. Advertising

  3. DC Gringo

    Andy Smith Guest

    Check out my free ListLink control.
    http://www.metabuilders.com/tools/ListLink.aspx

    __
    Andy Smith

    "Jairo Nieto" <> wrote in message
    news:#...
    > 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" <> wrote in message
    > news:...
    > > 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
    > >
    > >

    >
    >
     
    Andy Smith, Mar 6, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. DC Gringo
    Replies:
    2
    Views:
    510
    Andy Smith
    Mar 6, 2004
  2. mr2_93
    Replies:
    1
    Views:
    3,601
    mr2_93
    Oct 2, 2005
  3. tshad
    Replies:
    8
    Views:
    2,235
    tshad
    Oct 19, 2005
  4. DC Gringo

    best way to query on dropdownlist with another

    DC Gringo, Mar 4, 2004, in forum: ASP .Net Building Controls
    Replies:
    2
    Views:
    157
    Andy Smith
    Mar 6, 2004
  5. Eddy Xu
    Replies:
    5
    Views:
    124
    Eddy Xu
    Apr 11, 2008
Loading...

Share This Page