problem how to pass value from one procedure to another

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

    problem how to pass value from one procedure to another

    Hi,

    I create 5 dropdownlist in code-behind. I want to insert their
    selectedvalues in a table by making a string separated with ":"
    I can get their selecedvalues but i'm stuck when i want to execute the
    insert.
    The error is "name dd is not declared" (in line: selvalue = selvalue &
    Session("dd" & dd.id) & ":"

    Any idea how to solve this?
    Thanks for help
    Dan

    Dim dd() As DropDownList
    Dim i As Integer

    for i= 1 to 5
    dd(i) = New DropDownList
    dd(i).ID = id 'can be anything
    next

    For Each d As DropDownList In dds
    AddHandler d.SelectedIndex Changed, AddressOf dropd
    Next

    Protected Sub dropd(ByVal sender As Object, ByVal e As System.EventArg s)
    Dim dd As DropDownList = CType(sender, DropDownList)
    Session("dd" & id) = dd.SelectedValu e
    End Sub

    Protected Sub submit_Click(By Val sender As Object, ByVal e As
    System.EventArg s)
    Dim i As Integer
    Dim selvalue As String
    For i = 1 To 5
    selvalue = selvalue & Session("dd" & dd.id) & ":"
    Next
    sql="insert ....."
    ....






  • Cor Ligthert[MVP]

    #2
    Re: problem how to pass value from one procedure to another

    Dan,

    I don't know what other errrors there can be, but in my idea is dd (the
    dropdownList) not declared, in all other methods you are getting it from the
    sender or declare it new.

    Cor

    "Dan" <d@ny.nlschre ef in bericht
    news:OmYOOFsuIH A.3792@TK2MSFTN GP02.phx.gbl...
    Hi,
    >
    I create 5 dropdownlist in code-behind. I want to insert their
    selectedvalues in a table by making a string separated with ":"
    I can get their selecedvalues but i'm stuck when i want to execute the
    insert.
    The error is "name dd is not declared" (in line: selvalue = selvalue &
    Session("dd" & dd.id) & ":"
    >
    Any idea how to solve this?
    Thanks for help
    Dan
    >
    Dim dd() As DropDownList
    Dim i As Integer
    >
    for i= 1 to 5
    dd(i) = New DropDownList
    dd(i).ID = id 'can be anything
    next
    >
    For Each d As DropDownList In dds
    AddHandler d.SelectedIndex Changed, AddressOf dropd
    Next
    >
    Protected Sub dropd(ByVal sender As Object, ByVal e As System.EventArg s)
    Dim dd As DropDownList = CType(sender, DropDownList)
    Session("dd" & id) = dd.SelectedValu e
    End Sub
    >
    Protected Sub submit_Click(By Val sender As Object, ByVal e As
    System.EventArg s)
    Dim i As Integer
    Dim selvalue As String
    For i = 1 To 5
    selvalue = selvalue & Session("dd" & dd.id) & ":"
    Next
    sql="insert ....."
    ...
    >
    >
    >
    >
    >
    >

    Comment

    • Steve Gerrard

      #3
      Re: problem how to pass value from one procedure to another

      Inline comments:

      Dan wrote:
      Hi,
      >
      I create 5 dropdownlist in code-behind. I want to insert their
      selectedvalues in a table by making a string separated with ":"
      I can get their selecedvalues but i'm stuck when i want to execute the
      insert.
      The error is "name dd is not declared" (in line: selvalue = selvalue &
      Session("dd" & dd.id) & ":"
      >
      Any idea how to solve this?
      Dim dd() As DropDownList
      Dim i As Integer
      >
      for i= 1 to 5
      dd(i) = New DropDownList
      dd(i).ID = id 'can be anything
      next
      What is id? It is not declared anywhere, and is never assigned a value. In every
      sense of the word, it is nothing. It would make more sense to write something
      like
      dd(i).ID = i
      which would assign the value of i to the ID property of the dropdown.

      Protected Sub dropd(ByVal sender As Object, ByVal e As
      System.EventArg s) Dim dd As DropDownList = CType(sender, DropDownList)
      Session("dd" & id) = dd.SelectedValu e
      End Sub
      Again, what is id? It is not declared anywhere, and is never assigned a value.
      In every sense of the word, it is nothing. It would make more sense to write
      something like
      Session("dd" & dd.ID) = dd.SelectedValu e
      which would store the selected value in a session variable with the name ddx,
      where x is the value of the ID property of the drop down, as assigned in the
      previous loop above.

      >
      Protected Sub submit_Click(By Val sender As Object, ByVal e As
      System.EventArg s)
      Dim i As Integer
      Dim selvalue As String
      For i = 1 To 5
      selvalue = selvalue & Session("dd" & dd.id) & ":"
      Next
      sql="insert ....."
      This is closer, in that dd.id is presumably an attempt to get the ID property of
      a drop down. Unfortunately, dd itself is never declared, and never assigned a
      value, and this time it is dd that is nothing. It would make more sense to write
      selvalue = selvalue & Session("dd" & i)
      which will retrieve each of the 5 values stored in session variables by the
      event handler above - if all five have been set.

      It might be a good idea to store something in the Session variables for all 5 to
      start with, in case some of them never get set. The first loop would be a
      suitable place to do that.


      Comment

      • Dan

        #4
        Re: problem how to pass value from one procedure to another

        Thanks for replying.
        I think my explanation was not good enough. I ommitted some code to restrict
        the message.

        This is the real problem: there are a unknown number of dropdownlist
        (questions of a survey) (i took 5 as example) depending of the user who
        create the questions.
        The dropdownlists (some are not visible) have the property AutoPostBack =
        true, because the value of dropdownlist x can make another further
        dropdownlist visible. So each time an user introduces a value, the depending
        DD will be visible or remains unvisible. This is solved.

        Now, i want to collect all the selectedvalues and put them into a table.
        But i can't find a way to pass the collected selectedvalues in the submit
        procedure.


        Friend dds As New List(Of DropDownList)
        ....
        Dim dd() As DropDownList

        For i = 1 To (number of dropdownlist)
        dd(i) = New DropDownList
        dd(i).ID = id 'id is the id of the related quesion in the table
        dd(i).AutoPostB ack = True
        'fed from table
        ....
        form1.Controls. Add(dd(i))
        ....

        For Each d As DropDownList In dds
        AddHandler d.SelectedIndex Changed, AddressOf dropd
        Next

        Protected Sub dropd(ByVal sender As Object, ByVal e As System.EventArg s)
        Dim dd As DropDownList = CType(sender, DropDownList)
        session(dd.ID)= dd.selectedValu e
        End Sub

        Protected Sub submit_Click(By Val sender As Object, ByVal e As
        System.EventArg s)
        'how to get the selectvalue here?
        End Sub

        Thanks


        "Steve Gerrard" <mynamehere@com cast.netschreef in bericht
        news:p6CdnWrnOs DbK67VnZ2dnUVZ_ hjinZ2d@comcast .com...
        Inline comments:
        >
        Dan wrote:
        >Hi,
        >>
        >I create 5 dropdownlist in code-behind. I want to insert their
        >selectedvalu es in a table by making a string separated with ":"
        >I can get their selecedvalues but i'm stuck when i want to execute the
        >insert.
        >The error is "name dd is not declared" (in line: selvalue = selvalue &
        >Session("dd" & dd.id) & ":"
        >>
        >Any idea how to solve this?
        >
        >
        >Dim dd() As DropDownList
        >Dim i As Integer
        >>
        >for i= 1 to 5
        >dd(i) = New DropDownList
        >dd(i).ID = id 'can be anything
        >next
        >
        What is id? It is not declared anywhere, and is never assigned a value. In
        every sense of the word, it is nothing. It would make more sense to write
        something like
        dd(i).ID = i
        which would assign the value of i to the ID property of the dropdown.
        >
        >
        >Protected Sub dropd(ByVal sender As Object, ByVal e As
        >System.EventAr gs) Dim dd As DropDownList = CType(sender, DropDownList)
        >Session("dd" & id) = dd.SelectedValu e
        >End Sub
        >
        Again, what is id? It is not declared anywhere, and is never assigned a
        value. In every sense of the word, it is nothing. It would make more sense
        to write something like
        Session("dd" & dd.ID) = dd.SelectedValu e
        which would store the selected value in a session variable with the name
        ddx, where x is the value of the ID property of the drop down, as assigned
        in the previous loop above.
        >
        >
        >>
        >Protected Sub submit_Click(By Val sender As Object, ByVal e As
        >System.EventAr gs)
        >Dim i As Integer
        >Dim selvalue As String
        >For i = 1 To 5
        >selvalue = selvalue & Session("dd" & dd.id) & ":"
        >Next
        >sql="insert ....."
        >
        This is closer, in that dd.id is presumably an attempt to get the ID
        property of a drop down. Unfortunately, dd itself is never declared, and
        never assigned a value, and this time it is dd that is nothing. It would
        make more sense to write
        selvalue = selvalue & Session("dd" & i)
        which will retrieve each of the 5 values stored in session variables by
        the event handler above - if all five have been set.
        >
        It might be a good idea to store something in the Session variables for
        all 5 to start with, in case some of them never get set. The first loop
        would be a suitable place to do that.
        >
        >

        Comment

        • Andrew Morton

          #5
          Re: problem how to pass value from one procedure to another

          Dan wrote:
          Protected Sub submit_Click(By Val sender As Object, ByVal e As
          System.EventArg s)
          'how to get the selectvalue here?
          I think you need something like DirectCast(send er,
          DropDownList).S electedValue (and I hope you have Option Strict On at the top
          of the script).

          Andrew


          Comment

          • Andrew Morton

            #6
            Re: problem how to pass value from one procedure to another

            Dan wrote:
            Thanks but i don't understand what you mean.
            Ignore what I wrote - it was rubbish. It is Steve Gerrard's post that makes
            sense.

            Andrew


            Comment

            • Cor Ligthert[MVP]

              #7
              Re: problem how to pass value from one procedure to another

              Andrew,

              Just ignoring my post?

              As the computer tells,
              The error is "name dd is not declared" (in line: selvalue = selvalue &
              Session("dd" & dd.id) & ":"
              In the procedure

              Protected Sub submit_Click(By Val sender As Object, ByVal e As
              System.EventArg s)
              Dim i As Integer
              Dim selvalue As String
              For i = 1 To 5
              selvalue = selvalue & Session("dd" & dd.id) & ":"
              Next
              sql="insert ....."

              Then it has nothing to do with an ID, it is as is told. The object dd is not
              declared.
              And as we could see that it was declared in another method the change that
              it is a global object is low.

              Cor



              "Andrew Morton" <akm@in-press.co.uk.inv alidschreef in bericht
              news:69ismjF30n 7jiU1@mid.indiv idual.net...
              Dan wrote:
              >Thanks but i don't understand what you mean.
              >
              Ignore what I wrote - it was rubbish. It is Steve Gerrard's post that
              makes sense.
              >
              Andrew
              >

              Comment

              • Dan

                #8
                Re: problem how to pass value from one procedure to another

                Cor,

                i don't ignore your post, but please, forget Andrew and give me at least a
                hint (i reformulated the global problem two posts above.
                Thanks


                "Cor Ligthert[MVP]" <notmyfirstname @planet.nlschre ef in bericht
                news:BFAA157B-0054-48BB-A08C-15CCD457F7FA@mi crosoft.com...
                Andrew,
                >
                Just ignoring my post?
                >
                As the computer tells,
                >The error is "name dd is not declared" (in line: selvalue = selvalue &
                >Session("dd" & dd.id) & ":"
                >
                In the procedure
                >
                Protected Sub submit_Click(By Val sender As Object, ByVal e As
                System.EventArg s)
                Dim i As Integer
                Dim selvalue As String
                For i = 1 To 5
                selvalue = selvalue & Session("dd" & dd.id) & ":"
                Next
                sql="insert ....."
                >
                Then it has nothing to do with an ID, it is as is told. The object dd is
                not declared.
                And as we could see that it was declared in another method the change that
                it is a global object is low.
                >
                Cor
                >
                >
                >
                "Andrew Morton" <akm@in-press.co.uk.inv alidschreef in bericht
                news:69ismjF30n 7jiU1@mid.indiv idual.net...
                >Dan wrote:
                >>Thanks but i don't understand what you mean.
                >>
                >Ignore what I wrote - it was rubbish. It is Steve Gerrard's post that
                >makes sense.
                >>
                >Andrew
                >>
                >

                Comment

                • Cor Ligthert[MVP]

                  #9
                  Re: problem how to pass value from one procedure to another

                  Dan,

                  In my idea are you thinking that dd is a dropdownlist box, but it is not
                  even declared in your procedure somewhere else you write.

                  dim dd as dropdownlist = DirectCast(send er, DropdownList)
                  (You use CType, but DirectCast is better in this case because it does not
                  have to convert, the sender is your dropdownlist in an object)

                  I have the idea that it is something the same.

                  Cor

                  "Dan" <d@ny.nlschre ef in bericht
                  news:eTq7E$2uIH A.552@TK2MSFTNG P06.phx.gbl...
                  Cor,
                  >
                  i don't ignore your post, but please, forget Andrew and give me at least a
                  hint (i reformulated the global problem two posts above.
                  Thanks
                  >
                  >
                  "Cor Ligthert[MVP]" <notmyfirstname @planet.nlschre ef in bericht
                  news:BFAA157B-0054-48BB-A08C-15CCD457F7FA@mi crosoft.com...
                  >Andrew,
                  >>
                  >Just ignoring my post?
                  >>
                  >As the computer tells,
                  >>The error is "name dd is not declared" (in line: selvalue = selvalue &
                  >>Session("dd " & dd.id) & ":"
                  >>
                  >In the procedure
                  >>
                  >Protected Sub submit_Click(By Val sender As Object, ByVal e As
                  >System.EventAr gs)
                  >Dim i As Integer
                  >Dim selvalue As String
                  >For i = 1 To 5
                  >selvalue = selvalue & Session("dd" & dd.id) & ":"
                  >Next
                  >sql="insert ....."
                  >>
                  >Then it has nothing to do with an ID, it is as is told. The object dd is
                  >not declared.
                  >And as we could see that it was declared in another method the change
                  >that it is a global object is low.
                  >>
                  >Cor
                  >>
                  >>
                  >>
                  >"Andrew Morton" <akm@in-press.co.uk.inv alidschreef in bericht
                  >news:69ismjF30 n7jiU1@mid.indi vidual.net...
                  >>Dan wrote:
                  >>>Thanks but i don't understand what you mean.
                  >>>
                  >>Ignore what I wrote - it was rubbish. It is Steve Gerrard's post that
                  >>makes sense.
                  >>>
                  >>Andrew
                  >>>
                  >>
                  >
                  >

                  Comment

                  • Steve Gerrard

                    #10
                    Re: problem how to pass value from one procedure to another

                    Dan wrote:
                    >
                    Protected Sub dropd(ByVal sender As Object, ByVal e As
                    System.EventArg s) Dim dd As DropDownList = CType(sender, DropDownList)
                    session(dd.ID)= dd.selectedValu e
                    End Sub
                    >
                    Protected Sub submit_Click(By Val sender As Object, ByVal e As
                    System.EventArg s)
                    'how to get the selectvalue here?
                    End Sub
                    >
                    Okay, at the submit_Click event, the sender is the submit button, so that is no
                    help. You have two choices: look through the dropdowns themselves, or look in
                    the Session object. If you are maintaining ViewState, the dropdowns should be
                    present and have the current SelectedValue. Your dropd event handler will also
                    have stored any that changed in the Session object, if you are using that
                    instead.

                    If you are going to use ViewState, you don't need the event handler to store
                    anything in Session. Just gather the selected values from your dd array of drop
                    down lists.

                    If you are going to use the Session object, you should initialize it with the
                    initial values of all the dropdown selected values, so there is one value for
                    each drop down. That will get updated if any are changed by the user, using your
                    event. Then you can retrieve all the selected values from the Session object in
                    your submit event. Since you assigned IDs to the dropdowns from a table of
                    questions, you can use the same table to come up with the IDs you need to
                    retrieve the stored values.
                    Air code for that looks like
                    For each nID in tableOfQuestion IDs
                    selvalue = selvalue & Session(nID) & ":"
                    Next nID


                    Comment

                    • Dan

                      #11
                      Re: problem how to pass value from one procedure to another

                      Thanks

                      "Steve Gerrard" <mynamehere@com cast.netschreef in bericht
                      news:e76dnXTgsP HQY6nVnZ2dnUVZ_ srinZ2d@comcast .com...
                      Dan wrote:
                      >>
                      >Protected Sub dropd(ByVal sender As Object, ByVal e As
                      >System.EventAr gs) Dim dd As DropDownList = CType(sender, DropDownList)
                      >session(dd.ID) =dd.selectedVal ue
                      >End Sub
                      >>
                      >Protected Sub submit_Click(By Val sender As Object, ByVal e As
                      >System.EventAr gs)
                      >'how to get the selectvalue here?
                      >End Sub
                      >>
                      >
                      Okay, at the submit_Click event, the sender is the submit button, so that
                      is no help. You have two choices: look through the dropdowns themselves,
                      or look in the Session object. If you are maintaining ViewState, the
                      dropdowns should be present and have the current SelectedValue. Your dropd
                      event handler will also have stored any that changed in the Session
                      object, if you are using that instead.
                      >
                      If you are going to use ViewState, you don't need the event handler to
                      store anything in Session. Just gather the selected values from your dd
                      array of drop down lists.
                      >
                      If you are going to use the Session object, you should initialize it with
                      the initial values of all the dropdown selected values, so there is one
                      value for each drop down. That will get updated if any are changed by the
                      user, using your event. Then you can retrieve all the selected values from
                      the Session object in your submit event. Since you assigned IDs to the
                      dropdowns from a table of questions, you can use the same table to come up
                      with the IDs you need to retrieve the stored values.
                      Air code for that looks like
                      For each nID in tableOfQuestion IDs
                      selvalue = selvalue & Session(nID) & ":"
                      Next nID
                      >
                      >

                      Comment

                      Working...