Tough question for expert

Discussion in 'ASP .Net' started by jonny, Sep 25, 2009.

  1. jonny

    jonny Guest

    I have two dropdown controls and one sql table with column 1 & 2. I
    would like dropdown2 selection to be based on the selected item in
    dropdown1.

    For example, if dropdown1 selection is "oee" then I would like
    dropdown2 to only show selection for items in the table column 2 where
    column 1 has "oee" listed.

    So what I am having trouble with is the connection string where I only
    want to return items where equal to dropdown1 value...see my
    connection string here:

    Dim sql As String = "SELECT distinct column2 FROM MyTable Where
    column1 = webform.dropdown1"

    I think i am hung up here where I am using the actual value in
    dropdown1 on webform in my sql connection string...

    Please advise.
     
    jonny, Sep 25, 2009
    #1
    1. Advertising

  2. If you mean something like this :

    http://asp.net.do/test/DependListBoxes.aspx

    I can post the code...



    Juan T. Llibre, asp.net MVP
    ¿ Estas probando VS 2010 y ASP.NET 4.0 ?
    Regístrate (gratis) en los Foros de VS 2010 y ASP.NET 4.0, en español
    http://asp.net.do/foros/forums/
    =====================================================
    "jonny" <> wrote in message news:...
    >I have two dropdown controls and one sql table with column 1 & 2. I
    > would like dropdown2 selection to be based on the selected item in
    > dropdown1.
    >
    > For example, if dropdown1 selection is "oee" then I would like
    > dropdown2 to only show selection for items in the table column 2 where
    > column 1 has "oee" listed.
    >
    > So what I am having trouble with is the connection string where I only
    > want to return items where equal to dropdown1 value...see my
    > connection string here:
    >
    > Dim sql As String = "SELECT distinct column2 FROM MyTable Where
    > column1 = webform.dropdown1"
    >
    > I think i am hung up here where I am using the actual value in
    > dropdown1 on webform in my sql connection string...
    >
    > Please advise.
     
    Juan T. Llibre, Sep 25, 2009
    #2
    1. Advertising

  3. jonny <> wrote in news:2161b3c2-9866-4745-ab54-
    :

    > I have two dropdown controls and one sql table with column 1 & 2. I
    > would like dropdown2 selection to be based on the selected item in
    > dropdown1.
    >
    > For example, if dropdown1 selection is "oee" then I would like
    > dropdown2 to only show selection for items in the table column 2 where
    > column 1 has "oee" listed.
    >
    > So what I am having trouble with is the connection string where I only
    > want to return items where equal to dropdown1 value...see my
    > connection string here:
    >
    > Dim sql As String = "SELECT distinct column2 FROM MyTable Where
    > column1 = webform.dropdown1"
    >
    > I think i am hung up here where I am using the actual value in
    > dropdown1 on webform in my sql connection string...
    >
    > Please advise.


    Not exactly what you are aiming at, but it can give you some ideas to
    help you:
    http://snurl.com/s4d5r

    If you can use drop downs for each of the levels, it will do, however.


    --
    Gregory A. Beamer
    MVP; MCP: +I, SE, SD, DBA

    Twitter: @gbworld
    Blog: http://gregorybeamer.spaces.live.com

    My vacation and childhood cancer awareness site:
    http://www.crazycancertour.com

    *******************************************
    | Think outside the box! |
    *******************************************
     
    Gregory A. Beamer, Sep 25, 2009
    #3
  4. jonny

    Patrice Guest

    A descriptive subject would be better...

    A SQL statement knows nothing about your web page. Keep in mind that it will
    be send to your database server where it will run. So it has in no way
    access to the web server and even less to the intimate details of the
    originating web page.

    You have to feed the value taken from DropDown1.SelectedValue into your SQL
    statement likely using a parametized query (see the ADO.NET doc or
    http://aspnet101.com/aspnet101/tutorials.aspx?id=1). Basically the idea is
    that the SQL Server will have to receive the actual value for your dropdown.
    Though concatening strings could work this is not a best practice (as it
    could be easy for an attaquer to alter the input string to alter the
    statement SQL send to the server in an harmfull way).

    As a side note this is rather just a SQL statement (a connection string is
    the string that defines the *connection* information not the SQL statement
    you send to a server).

    --
    Patrice

    "jonny" <> a écrit dans le message de groupe de
    discussion :
    ...
    > I have two dropdown controls and one sql table with column 1 & 2. I
    > would like dropdown2 selection to be based on the selected item in
    > dropdown1.
    >
    > For example, if dropdown1 selection is "oee" then I would like
    > dropdown2 to only show selection for items in the table column 2 where
    > column 1 has "oee" listed.
    >
    > So what I am having trouble with is the connection string where I only
    > want to return items where equal to dropdown1 value...see my
    > connection string here:
    >
    > Dim sql As String = "SELECT distinct column2 FROM MyTable Where
    > column1 = webform.dropdown1"
    >
    > I think i am hung up here where I am using the actual value in
    > dropdown1 on webform in my sql connection string...
    >
    > Please advise.
    >
     
    Patrice, Sep 25, 2009
    #4
  5. jonny

    jonny Guest

    On Sep 25, 8:25 am, "Juan T. Llibre" <>
    wrote:
    > If you mean something like this :
    >
    > http://asp.net.do/test/DependListBoxes.aspx
    >
    > I can post the code...
    >
    > Juan T. Llibre, asp.net MVP
    > ¿ Estas probando VS 2010 y ASP.NET 4.0 ?
    > Regístrate (gratis) en los Foros de VS 2010 y ASP.NET 4.0, en españolhttp://asp.net.do/foros/forums/
    > =====================================================
    >
    > "jonny" <> wrote in messagenews:...
    > >I have two dropdown controls and one sql table with column 1 & 2. I
    > > would like dropdown2 selection to be based on the selected item in
    > > dropdown1.

    >
    > > For example, if dropdown1 selection is "oee" then I would like
    > > dropdown2 to only show selection for items in the table column 2 where
    > > column 1 has "oee" listed.

    >
    > > So what I am having trouble with is the connection string where I only
    > > want to return items where equal to dropdown1 value...see my
    > > connection string here:

    >
    > > Dim sql As String = "SELECT distinct column2 FROM MyTable Where
    > > column1 =  webform.dropdown1"

    >
    > > I think i am hung up here where I am using the actual value in
    > > dropdown1 on webform in my sql connection string...

    >
    > > Please advise.


    Yes that is what I want to do only using dropdowns rather than
    listbox. Yes please post code I appreciate your help with this
    struggle.
     
    jonny, Sep 25, 2009
    #5
  6. jonny

    jonny Guest

    On Sep 25, 8:37 am, "Gregory A. Beamer"
    <> wrote:
    > jonny <> wrote in news:2161b3c2-9866-4745-ab54-
    > :
    >
    >
    >
    > > I have two dropdown controls and one sql table with column 1 & 2. I
    > > would like dropdown2 selection to be based on the selected item in
    > > dropdown1.

    >
    > > For example, if dropdown1 selection is "oee" then I would like
    > > dropdown2 to only show selection for items in the table column 2 where
    > > column 1 has "oee" listed.

    >
    > > So what I am having trouble with is the connection string where I only
    > > want to return items where equal to dropdown1 value...see my
    > > connection string here:

    >
    > > Dim sql As String = "SELECT distinct column2 FROM MyTable Where
    > > column1 =  webform.dropdown1"

    >
    > > I think i am hung up here where I am using the actual value in
    > > dropdown1 on webform in my sql connection string...

    >
    > > Please advise.

    >
    > Not exactly what you are aiming at, but it can give you some ideas to
    > help you:http://snurl.com/s4d5r
    >
    > If you can use drop downs for each of the levels, it will do, however.
    >
    > --
    > Gregory A. Beamer
    > MVP; MCP: +I, SE, SD, DBA
    >
    > Twitter: @gbworld
    > Blog:http://gregorybeamer.spaces.live.com
    >
    > My vacation and childhood cancer awareness site:http://www.crazycancertour.com
    >
    > *******************************************
    > |      Think outside the box!             |
    > *******************************************


    Gregory,

    Thanks for your post. I do not see the cascadingdropdown control in my
    toolbox. How do I get it there?
     
    jonny, Sep 25, 2009
    #6
  7. jonny

    jonny Guest

    On Sep 25, 9:13 am, "Patrice" <http://scribe-en.blogspot.com/> wrote:
    > A descriptive subject would be better...
    >
    > A SQL statement knows nothing about your web page. Keep in mind that it will
    > be send to your database server where it will run. So it has in no way
    > access to the web server and even less to the intimate details of the
    > originating web page.
    >
    > You have to feed the value taken from DropDown1.SelectedValue into your SQL
    > statement likely using a parametized query (see the ADO.NET doc orhttp://aspnet101.com/aspnet101/tutorials.aspx?id=1). Basically the idea is
    > that the SQL Server will have to receive the actual value for your dropdown.
    > Though concatening strings could work this is not a best practice (as it
    > could be easy for an attaquer to alter the input string to alter the
    > statement SQL send to the server in an harmfull way).
    >
    > As a side note this is rather just a SQL statement (a connection string is
    > the string that defines the *connection* information not the SQL statement
    > you send to a server).
    >
    > --
    > Patrice
    >
    > "jonny" <> a écrit dans le message de groupe de
    > discussion :
    > ...
    >
    > > I have two dropdown controls and one sql table with column 1 & 2. I
    > > would like dropdown2 selection to be based on the selected item in
    > > dropdown1.

    >
    > > For example, if dropdown1 selection is "oee" then I would like
    > > dropdown2 to only show selection for items in the table column 2 where
    > > column 1 has "oee" listed.

    >
    > > So what I am having trouble with is the connection string where I only
    > > want to return items where equal to dropdown1 value...see my
    > > connection string here:

    >
    > > Dim sql As String = "SELECT distinct column2 FROM MyTable Where
    > > column1 =  webform.dropdown1"

    >
    > > I think i am hung up here where I am using the actual value in
    > > dropdown1 on webform in my sql connection string...

    >
    > > Please advise.


    Thanks Patrice,

    But I am writing this sql query on a separate page and call it up with
    the code from form where dropdown is at, otherwise this code below
    would work

    sql = "Select * from Employees where Lastname = '" &
    ddl.selecteditem.text & "'"

    However, again I am writing the query on another page so it would need
    to be something like...

    sql = "Select * from Employees where Lastname = '" &
    FORM1.ddl.selecteditem.text & "'"

    But the problem is I do not know how to get this page I am writing the
    query on to recognize the web form where i have the dropdown control.
    Please advise.
     
    jonny, Sep 25, 2009
    #7
  8. jonny

    Patrice Guest


    > sql = "Select * from Employees where Lastname = '" &
    > ddl.selecteditem.text & "'"


    Ok this is not what in your shown in your first.

    > However, again I am writing the query on another page so it would need
    > to be something like...


    You never mentioned this in your first post.

    > But the problem is I do not know how to get this page I am writing the
    > query on to recognize the web form where i have the dropdown control.


    Ah, this is not the problem In thought you had. It would be then :

    http://msdn.microsoft.com/en-us/library/6c3yckfw(VS.80).aspx (How to: Pass
    Values Between ASP.NET Web Pages )

    --
    Patrice
     
    Patrice, Sep 25, 2009
    #8
  9. jonny

    Patrice Guest

    > However, again I am writing the query on another page so it would need
    > to be something like...


    As a side note you may want to double check posting to another page is your
    best option. It could be more natural to post to the same page plus if you
    are still on the two related dropdown issue if the user change his mind it
    could be easier for him to just reselected another value in the first
    dropdown rather than having to go back to the first page (if you are no more
    in this scenerio you may want to iopen a new thread so that we don't believe
    this is still what you are trying to do).

    You also have an ASP.NET control that allows to create a wizard like process
    using a single page (with next/previous/finish buttons depending on the
    current step).

    --
    Patrice
     
    Patrice, Sep 25, 2009
    #9
  10. jonny <> wrote in
    news::


    > Thanks for your post. I do not see the cascadingdropdown control in my
    > toolbox. How do I get it there?



    Download the AASP.NET AJAX toolkit from www.asp.net/ajax

    peace and grace,


    --
    Gregory A. Beamer
    MVP; MCP: +I, SE, SD, DBA

    Twitter: @gbworld
    Blog: http://gregorybeamer.spaces.live.com

    My vacation and childhood cancer awareness site:
    http://www.crazycancertour.com

    *******************************************
    | Think outside the box! |
    *******************************************
     
    Gregory A. Beamer, Sep 25, 2009
    #10
    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. M O J O
    Replies:
    2
    Views:
    295
    M O J O
    Aug 6, 2003
  2. Dot net work

    Tough redirection question

    Dot net work, Apr 11, 2004, in forum: ASP .Net
    Replies:
    4
    Views:
    468
    Dot net work
    Apr 12, 2004
  3. GaryB

    Really tough Crystal Question

    GaryB, Nov 16, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    344
    Steven Cheng[MSFT]
    Nov 17, 2004
  4. JSF Tough Question

    , Jan 20, 2005, in forum: Java
    Replies:
    2
    Views:
    608
  5. Replies:
    1
    Views:
    437
    Eugene Druker
    Jun 14, 2005
Loading...

Share This Page