Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Professional
|
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 20th, 2008, 04:40 PM
Friend of Wrox
 
Join Date: Apr 2006
Posts: 160
Thanks: 0
Thanked 0 Times in 0 Posts
Default how to pass value to submit procedure?

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
H.

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 ....."
...






 
Old May 21st, 2008, 06:10 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Couple of problems here. First the variable dd is out of scope of your Submit_Click method. (I am assuming the code where you populate the array is in another method, the Page_Load perhaps?) Since you are dynamically creating teh controls I can see why you keep building them, my suggestion would be to make dd a class level variable so that it has scope to all of the methods in your class.

Second, your loop won't achieve what you want it to. You should change your code to:
selvalue = selvalue & Session("dd" & dd(i).id) & ":"

hth.
-Doug

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
.: Wrox Technical Editor / Author :.
Wrox Books 24 x 7
================================================== =========
 
Old May 21st, 2008, 08:44 AM
Friend of Wrox
 
Join Date: Apr 2006
Posts: 160
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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)
[u]'how to get the selectvalue here?</u>
End Sub

Thanks







Similar Threads
Thread Thread Starter Forum Replies Last Post
how to pass value to stored procedure? hertendreef SQL Server 2005 3 February 23rd, 2007 11:43 AM
How to pass a parameter to a stored procedure? MaxGay2 VB.NET 2002/2003 Basics 1 November 8th, 2006 02:48 PM
Can you pass a table to a store procedure? pbyrum SQL Language 1 January 26th, 2005 01:43 PM
How will I pass stored procedure in an asp shoakat SQL Server 2000 1 July 15th, 2004 10:28 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.