473,396 Members | 1,804 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 with variable scope in aspx page

I'm trying to check for "No Records Found" in a repeater list control,
but my 'numrows' variable cannot be seen by the function CheckNoR ,
even tho it's public (?) . I've been informed that the page class has
to have these declared as member variables, but still cannot see why
this won't work:

<script runat="server">
'Handle page load event
public Sub Page_Load(Sender As Object, E As EventArgs)

Dim MyConnection As SQLConnection
Dim MyCommand As SQLDataAdapter
dim MyDataset As DataSet
dim MyTable As DataTable
dim numrows As Integer
dim sqlstr As String
sqlstr = "SELECT company,city from customers "

MyConnection = New SqlConnection("Data
Source=dbase.net;Initial
Catalog=mydb;User Id=myuser;Password=mypwd;")

MyCommand = New SQLDataAdapter(sqlstr, MyConnection)

' Create a Command object with the SQL statement.
MyCommand = New SQLDataAdapter(sqlstr, MyConnection)

' Fill a DataSet with data returned from the database.
MyDataset = New DataSet
MyCommand.Fill(MyDataset)

' Create a new DataTable object and assign to it
' the new table in the Tables collection.

MyTable = New DataTable
MyTable = MyDataset.Tables(0)

''''tie it to my repeater control
dr.DataSource = MyTable
dr.DataBind()

MyConnection.Close

End Sub

</script>
<script runat="server">
function checkNoR(ByVal as String)
numrows = MyTable.Rows.Count
If numrows = 0 then
Response.Write("<p>No records.</p>")
End If
end function
</script>

Jul 11 '07 #1
1 1534
Just declare numrows as private just below
this line in your code (which is outside the Page_Load sub)
instead of inside the Page_Load sub.

'Handle page load event

--
Robbe Morris
..NET PropertyGrid Control - ListBox, ComboBox, and Custom Classes
http://www.eggheadcafe.com/tutorials...d-control.aspx


"mister-Ed" <27**@cox.netwrote in message
news:11**********************@d55g2000hsg.googlegr oups.com...
I'm trying to check for "No Records Found" in a repeater list control,
but my 'numrows' variable cannot be seen by the function CheckNoR ,
even tho it's public (?) . I've been informed that the page class has
to have these declared as member variables, but still cannot see why
this won't work:

<script runat="server">
'Handle page load event
public Sub Page_Load(Sender As Object, E As EventArgs)

Dim MyConnection As SQLConnection
Dim MyCommand As SQLDataAdapter
dim MyDataset As DataSet
dim MyTable As DataTable
dim numrows As Integer
dim sqlstr As String
sqlstr = "SELECT company,city from customers "

MyConnection = New SqlConnection("Data
Source=dbase.net;Initial
Catalog=mydb;User Id=myuser;Password=mypwd;")

MyCommand = New SQLDataAdapter(sqlstr, MyConnection)

' Create a Command object with the SQL statement.
MyCommand = New SQLDataAdapter(sqlstr, MyConnection)

' Fill a DataSet with data returned from the database.
MyDataset = New DataSet
MyCommand.Fill(MyDataset)

' Create a new DataTable object and assign to it
' the new table in the Tables collection.

MyTable = New DataTable
MyTable = MyDataset.Tables(0)

''''tie it to my repeater control
dr.DataSource = MyTable
dr.DataBind()

MyConnection.Close

End Sub

</script>
<script runat="server">
function checkNoR(ByVal as String)
numrows = MyTable.Rows.Count
If numrows = 0 then
Response.Write("<p>No records.</p>")
End If
end function
</script>
Aug 20 '07 #2

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

Similar topics

1
by: Andrew Pasetti | last post by:
I'm having trouble binding/displaying a class variable to the display aspx page. Perhaps someone can suggest what I am doing wrong. ################################### Within the .aspx page I...
2
by: John Holmes | last post by:
I have a web interface where the user types in ID's one at a time. After an ID is typed in, a button is clicked and the button click event has code that does a query and returns a data reader and...
3
by: Stuart | last post by:
Hi there I am using a button column>SELECT and a datagrid.Item_Command to take a value from the datagrid (in this case a customer account number) - store that value in to a session variable and...
1
by: Steve Wark | last post by:
If I create two aspx pages, place three text boxes (working with VS .net 2003 and web form controls) and a button on both forms. On the first page, the button is set to use the "onClick" to open...
0
by: Steve Wark | last post by:
If I create two aspx pages, place three text boxes (working with VS .net 2003 and web form controls) and a button on both forms. On the first page, the button is set to use the "onClick" to open...
1
by: Vidyadhar Joshi | last post by:
I have the following scenario in a true load balanced environment (without sticky sessions): There are 2 ASPX pages. I want to pass an object from the first page to the second page. On the...
2
by: Kamen | last post by:
Hello there, I try to define the properties font-size and font-bold of the pager of a gridview using the pagerstyle, but the settings are not appleyd at run time. What could be the reason for...
1
pbmods
by: pbmods | last post by:
VARIABLE SCOPE IN JAVASCRIPT LEVEL: BEGINNER/INTERMEDIATE (INTERMEDIATE STUFF IN ) PREREQS: VARIABLES First off, what the heck is 'scope' (the kind that doesn't help kill the germs that cause...
2
by: ray | last post by:
Hi, all, foreach($array as $k =$v) { $foo = ...; } echo $foo; Is it allowed to access the $foo variable that is created within the loop from outside of the loop? I think it isn't allowed,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
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.