locked
how to pass value to other procedure RRS feed

  • Question

  • User-1008348326 posted
    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
    T.
     
    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.SelectedIndexChanged, AddressOf dropd
    Next
     
    Protected Sub dropd(ByVal sender As Object, ByVal e As System.EventArgs)
    Dim dd As DropDownList = CType(sender, DropDownList)
    Session("dd" & id) = dd.SelectedValue
    End Sub
     
    Protected Sub submit_Click(ByVal sender As Object, ByVal e As System.EventArgs)
    Dim i As Integer
    Dim selvalue As String
    For i = 1 To 5
    selvalue = selvalue & Session("dd" & dd.id) & ":"
    Next
    sql="insert ....."
    ...
     
     
     

     
    Tuesday, May 20, 2008 5:35 PM

All replies

  • User-362017084 posted

    Hi tartuffe2,

     You have used dd(i)=New DropDownList

    Use -

    For i=1 To 5

    selvalue=selvalue & Session("dd" & dd(i).ID) & ":"

    Next

    Wednesday, May 21, 2008 3:07 AM
  • User-1008348326 posted

    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).AutoPostBack = True
    'fed from table
    ...
    form1.Controls.Add(dd(i))
    ...

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

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

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

    Thanks

    Wednesday, May 21, 2008 9:42 AM