473,396 Members | 2,109 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

problem how to pass value from one procedure to another

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


Jun 27 '08 #1
10 1520
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.nlschreef in bericht
news:Om**************@TK2MSFTNGP02.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.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 ....."
...

Jun 27 '08 #2
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.EventArgs) Dim dd As DropDownList = CType(sender, DropDownList)
Session("dd" & id) = dd.SelectedValue
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.SelectedValue
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(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 ....."
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.
Jun 27 '08 #3
Dan
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
"Steve Gerrard" <my********@comcast.netschreef in bericht
news:p6******************************@comcast.com. ..
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.EventArgs) Dim dd As DropDownList = CType(sender, DropDownList)
Session("dd" & id) = dd.SelectedValue
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.SelectedValue
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(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 ....."

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.


Jun 27 '08 #4
Dan wrote:
Protected Sub submit_Click(ByVal sender As Object, ByVal e As
System.EventArgs)
'how to get the selectvalue here?
I think you need something like DirectCast(sender,
DropDownList).SelectedValue (and I hope you have Option Strict On at the top
of the script).

Andrew
Jun 27 '08 #5
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
Jun 27 '08 #6
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(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 ....."

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" <ak*@in-press.co.uk.invalidschreef in bericht
news:69*************@mid.individual.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
Jun 27 '08 #7
Dan
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]" <no************@planet.nlschreef in bericht
news:BF**********************************@microsof t.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(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 ....."

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" <ak*@in-press.co.uk.invalidschreef in bericht
news:69*************@mid.individual.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

Jun 27 '08 #8
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(sender, 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.nlschreef in bericht
news:eT*************@TK2MSFTNGP06.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]" <no************@planet.nlschreef in bericht
news:BF**********************************@microsof t.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(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 ....."

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" <ak*@in-press.co.uk.invalidschreef in bericht
news:69*************@mid.individual.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

Jun 27 '08 #9
Dan wrote:
>
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
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 tableOfQuestionIDs
selvalue = selvalue & Session(nID) & ":"
Next nID
Jun 27 '08 #10
Dan
Thanks

"Steve Gerrard" <my********@comcast.netschreef in bericht
news:e7******************************@comcast.com. ..
Dan wrote:
>>
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

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 tableOfQuestionIDs
selvalue = selvalue & Session(nID) & ":"
Next nID


Jun 27 '08 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Toonman | last post by:
I'm trying to use a couple of variables in a stored procedure. Things work fine when I hard code the data into the variables and also work fine when I use the variable in the WHERE clause and hard...
1
by: Mark Dicken | last post by:
Hi All I have found the following Microsoft Technet 'Q' Article :- Q210368 -ACC2000: How to Pass an Array as an Argument to a Procedure (I've also copied and pasted the whole contents into...
7
by: Zlatko Matić | last post by:
Let's assume that we have a database on some SQL server (let it be MS SQL Server) and that we want to execute some parameterized query as a pass.through query. How can we pass parameters to the...
2
by: Mike Hutton | last post by:
I have a rather odd problem. I have a SP which uses temp. tables along the way, and then returns a table of results: CREATE PROCEDURE dbo.usp_myproc( @pNameList VARCHAR(6000) ) AS
7
by: Dabbler | last post by:
I'm using an ObjectDataSource with a stored procedure and am getting the following error when trying to update (ExecuteNonQuery): System.Data.SqlClient.SqlException: Procedure or Function...
7
by: Rudy | last post by:
Hello All! I have a value in a textbox(txbTableIDm.Text ) that I would like to use in a paremiter in a SP I wrote, and then have the select statement work off that parememter, retireive a...
12
by: Light | last post by:
Hi all, I posted this question in the sqlserver.newusers group but I am not getting any response there so I am going to try it on the fine folks here:). I inherited some legacy ASP codes in my...
0
by: nico3334 | last post by:
I am creating a report that pulls values from a SQL table in visual basic. I have 3 main procedures. The Main procedure PrintInitialize CALLS 2 other procedures during its coding: GetTempData...
2
by: pinman | last post by:
hi. i'm pretty much a noob to c# and visual studio and am trying to create a simple login method. i have created a users table in the database and can add users by inputing there md5 encrypted...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.