get values from drop down

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • John

    #1

    get values from drop down

    I have a drop down on my form and I need all the values in that drop down
    and pass to a stored procedure, how can I get the values of the drop down
    and pass them all to my stored procedure call?



  • Tasos Vogiatzoglou

    #2
    Re: get values from drop down

    You can't do that from a simple drop-down control because these values
    are not posted on the server. If you are talking about a server side
    drop-down, then enumerating through Items property for the ListItems of
    the control should give you the values.

    Regards,
    Tasos


    John wrote:[color=blue]
    > I have a drop down on my form and I need all the values in that drop down
    > and pass to a stored procedure, how can I get the values of the drop down
    > and pass them all to my stored procedure call?[/color]

    Comment

    • Karl Seguin [MVP]

      #3
      Re: get values from drop down

      Do you mean including the none-selected ones?

      If it's a server control (ie, asp:dropdownlis t) and you enable viewstate
      (which it is by default), you can simply loop through it's item collection..

      for each item as ListItem in myDropDown.Item s
      dim value as string = item.Value
      ..do something
      end for

      Otherwise, you'll need to use javascrit to highlight every item onSubmit and
      use Request.Form



      --
      Programming blog exploring Zig, Elixir, Go, Testing, Design and Performance




      "John" <whynow@gmail.c om> wrote in message
      news:OZEVbRLhGH A.4864@TK2MSFTN GP05.phx.gbl...[color=blue]
      >I have a drop down on my form and I need all the values in that drop down
      >and pass to a stored procedure, how can I get the values of the drop down
      >and pass them all to my stored procedure call?
      >
      >
      >[/color]


      Comment

      • John

        #4
        Re: get values from drop down

        its a user control:
        <asp:DropDownlL ist id="ddCars" runat="server"> </asp:DropDownLis t>
        when I do a foreach I get an error message


        "Tasos Vogiatzoglou" <tvoglou@gmail. com> wrote in message
        news:1149083628 .698489.186470@ g10g2000cwb.goo glegroups.com.. .[color=blue]
        > You can't do that from a simple drop-down control because these values
        > are not posted on the server. If you are talking about a server side
        > drop-down, then enumerating through Items property for the ListItems of
        > the control should give you the values.
        >
        > Regards,
        > Tasos
        >
        >
        > John wrote:[color=green]
        >> I have a drop down on my form and I need all the values in that drop down
        >> and pass to a stored procedure, how can I get the values of the drop down
        >> and pass them all to my stored procedure call?[/color]
        >[/color]


        Comment

        • Ray Booysen

          #5
          Re: get values from drop down

          Would you like to post your error message and the code?

          John wrote:[color=blue]
          > its a user control:
          > <asp:DropDownlL ist id="ddCars" runat="server"> </asp:DropDownLis t>
          > when I do a foreach I get an error message
          >
          >
          > "Tasos Vogiatzoglou" <tvoglou@gmail. com> wrote in message
          > news:1149083628 .698489.186470@ g10g2000cwb.goo glegroups.com.. .[color=green]
          >> You can't do that from a simple drop-down control because these values
          >> are not posted on the server. If you are talking about a server side
          >> drop-down, then enumerating through Items property for the ListItems of
          >> the control should give you the values.
          >>
          >> Regards,
          >> Tasos
          >>
          >>
          >> John wrote:[color=darkred]
          >>> I have a drop down on my form and I need all the values in that drop down
          >>> and pass to a stored procedure, how can I get the values of the drop down
          >>> and pass them all to my stored procedure call?[/color][/color]
          >
          >[/color]

          Comment

          • John

            #6
            Re: get values from drop down

            Error:

            Error 5 foreach statement cannot operate on variables of type
            'ASP.usercontro ls_carMakes_asc x' because 'ASP.usercontro ls_carMakes_asc x'
            does not contain a public definition for 'GetEnumerator'

            code on my form that has the user control on it:

            void btnGo_Click(obj ect sender, EventArgs e)
            {
            foreach (ListItem items in CarMake)
            {
            Response.Write( items.Value);
            }
            }
            and this is a dropdown box not a listbox

            "Ray Booysen" <rj_booysen_NS@ rjb.za.net> wrote in message
            news:%23WMa65Lh GHA.3572@TK2MSF TNGP04.phx.gbl. ..[color=blue]
            > Would you like to post your error message and the code?
            >
            > John wrote:[color=green]
            >> its a user control:
            >> <asp:DropDownlL ist id="ddCars" runat="server"> </asp:DropDownLis t>
            >> when I do a foreach I get an error message
            >>
            >>
            >> "Tasos Vogiatzoglou" <tvoglou@gmail. com> wrote in message
            >> news:1149083628 .698489.186470@ g10g2000cwb.goo glegroups.com.. .[color=darkred]
            >>> You can't do that from a simple drop-down control because these values
            >>> are not posted on the server. If you are talking about a server side
            >>> drop-down, then enumerating through Items property for the ListItems of
            >>> the control should give you the values.
            >>>
            >>> Regards,
            >>> Tasos
            >>>
            >>>
            >>> John wrote:
            >>>> I have a drop down on my form and I need all the values in that drop
            >>>> down
            >>>> and pass to a stored procedure, how can I get the values of the drop
            >>>> down
            >>>> and pass them all to my stored procedure call?[/color]
            >>[/color][/color]

            Comment

            • Ray Booysen

              #7
              Re: get values from drop down

              John wrote:[color=blue]
              > Error:
              >
              > Error 5 foreach statement cannot operate on variables of type
              > 'ASP.usercontro ls_carMakes_asc x' because 'ASP.usercontro ls_carMakes_asc x'
              > does not contain a public definition for 'GetEnumerator'
              >
              > code on my form that has the user control on it:
              >
              > void btnGo_Click(obj ect sender, EventArgs e)
              > {
              > foreach (ListItem items in CarMake)
              > {
              > Response.Write( items.Value);
              > }
              > }
              > and this is a dropdown box not a listbox[/color]
              Well, no its neither. As the error message shows, CarMake is of type
              ASP.usercontrol s_carMakes_ascx which is a user control that either you
              or your team has developed.

              Without further code as to the properties of this usercontrol, we can go
              no further.

              Kind Regards
              Ray

              [color=blue]
              >
              > "Ray Booysen" <rj_booysen_NS@ rjb.za.net> wrote in message
              > news:%23WMa65Lh GHA.3572@TK2MSF TNGP04.phx.gbl. ..[color=green]
              >> Would you like to post your error message and the code?
              >>
              >> John wrote:[color=darkred]
              >>> its a user control:
              >>> <asp:DropDownlL ist id="ddCars" runat="server"> </asp:DropDownLis t>
              >>> when I do a foreach I get an error message
              >>>
              >>>
              >>> "Tasos Vogiatzoglou" <tvoglou@gmail. com> wrote in message
              >>> news:1149083628 .698489.186470@ g10g2000cwb.goo glegroups.com.. .
              >>>> You can't do that from a simple drop-down control because these values
              >>>> are not posted on the server. If you are talking about a server side
              >>>> drop-down, then enumerating through Items property for the ListItems of
              >>>> the control should give you the values.
              >>>>
              >>>> Regards,
              >>>> Tasos
              >>>>
              >>>>
              >>>> John wrote:
              >>>>> I have a drop down on my form and I need all the values in that drop
              >>>>> down
              >>>>> and pass to a stored procedure, how can I get the values of the drop
              >>>>> down
              >>>>> and pass them all to my stored procedure call?[/color][/color]
              >[/color]

              Comment

              Working...