By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,287 Members | 1,668 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,287 IT Pros & Developers. It's quick & easy.

Can't get value from one function to another in Aspx page

P: n/a
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 (?)

<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 10 '07 #1
Share this Question
Share on Google+
4 Replies


P: n/a
mister-Ed wrote:
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 (?)

<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
MyTable is a local variable in the Page_Load method.
dim numrows As Integer
numrows is a local variable in the Page_Load method.
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
Neither numrows nor MyTable exist outside the Page_Load method.
If numrows = 0 then
Response.Write("<p>No records.</p>")
End If
end function
</script>

--
Göran Andersson
_____
http://www.guffa.com
Jul 10 '07 #2

P: n/a
Neither numrows nor MyTable exist outside the Page_Load method.
Well, yes, I need to find a way to make them available in the CheckNoR
function without having to re-declare all the ADO objects and
'numrows' and re-assign values
thanx
Ed

Jul 10 '07 #3

P: n/a
mister-Ed wrote:
>Neither numrows nor MyTable exist outside the Page_Load method.

Well, yes, I need to find a way to make them available in the CheckNoR
function without having to re-declare all the ADO objects and
'numrows' and re-assign values
thanx
Ed
Declare them as member variables in the page class.

--
Göran Andersson
_____
http://www.guffa.com
Jul 10 '07 #4

P: n/a
On Jul 10, 9:09 am, Göran Andersson <g...@guffa.comwrote:
mister-Ed wrote:
Neither numrows nor MyTable exist outside the Page_Load method.
Well, yes, I need to find a way to make them available in the CheckNoR
function without having to re-declare all the ADO objects and
'numrows' and re-assign values
thanx
Ed

Declare them as member variables in the page class.

--
Göran Andersson
_____http://www.guffa.com

Thanks for reply and help. ARE there any tutorials/helpful links that
explains how to do this?

Jul 10 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.