473,231 Members | 1,910 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,231 software developers and data experts.

Gridview not displaying data - please help!

Hi all,

I'm trying to develop an ASP.NET 2.0 website and am running into some
real problems with what I thought would be a relatively simple thing
to do.

In a nutshell, I'm stuck on trying to display data in a "GridView"
which is tied to an "ObjectDataSource".
In turn, this ObjectDatasource gets it's data from a strongly-typed
business object within my code.
I'm also trying to use custom paging, so my class has correctly
implemented methods to return the total count of records, and also the
method which retrieves the actual page of records is accepting two
parameters for the startRowIndex and maximumRows. I do NOT need any
sorting capability for this gridview, nor do I need any updating,
deleting, selecting functionality, either. I simply need to display
all the relevant records from the database (via my object), paged
(using SQL2005's ROW_NUMBER style paging).

I have this working beautifully when I use a strongly-typed dataset
for the ObjectDatasource's data, however, when I switch to using a
"business object", the Gridview doesn't seem to want to display any
data.

I can step through my code, and confirm that I am retrieving some
records from the database, which is then "returned" from the
"selectmethod" function call as a Generic List (ie. List(of T)).

Below, I've pasted some code that highlights my problem (I re-did the
code to focus on this one problem - in my real code, my DAL and BLL
are separate, whereas here they're in the same class, just for
brevity's sake). If your interested, you can download the entire
zipped up webproject (about 580kb) from here:
http://putstuff.putfile.com/17957/6448935
Has anyone encountered this problem before?? Does anyone know what
I'm doing wrong?? (I'm convinved it's something really simple that
I'm missing).

Any/all replies are greatly appreciated.
Regards,
Greg

The database has one table, as follows:

CREATE TABLE [dbo].[TestTable] (
[UniqueID] [uniqueidentifier] NOT NULL ,
[Name] [varchar] (50) NOT NULL ,
[BirthDate] [datetime] NOT NULL ,
[Comment] [varchar] (100) NOT NULL
)


There's 2 stored procedures, as follows:

ALTER PROCEDURE dbo.usp_GetTestTable
(
@startRowIndex int,
@maximumRows int
)

AS

SELECT UniqueID, [Name], BirthDate, Comment
FROM

(SELECT UniqueID, [Name], BirthDate, Comment, ROW_NUMBER()
OVER(ORDER BY BirthDate) AS RowNum
FROM TestTable
) AS TestTableList
WHERE RowNum BETWEEN @startRowIndex AND (@startRowIndex +
@maximumRows) - 1
and:

ALTER PROCEDURE dbo.usp_GetTestTableCount

AS

SELECT
COUNT(*)
FROM
TestTable


The "custom class" is defined as follows:

Imports Microsoft.VisualBasic
Imports System.Collections.Generic
Imports system.data
Imports System.Data.Sql
Imports system.Data.SqlClient

'
'
'
Public Class TestTableClass
'
'
Private m_UniqueID As String = ""
Private m_Name As String = ""
Private m_BirthDate As DateTime = Nothing
Private m_Comment As String = ""
'
'
Public Property UniqueID() As String
Get
Return m_UniqueID
End Get
Set(ByVal value As String)
m_UniqueID = value
End Set
End Property
'
Public Property Name() As String
Get
Return m_Name
End Get
Set(ByVal value As String)
m_Name = value
End Set
End Property
'
Public Property BirthDate() As DateTime
Get
Return m_BirthDate
End Get
Set(ByVal value As DateTime)
m_BirthDate = value
End Set
End Property
'
Public Property Comment() As String
Get
Return m_Comment
End Get
Set(ByVal value As String)
m_Comment = value
End Set
End Property
'
'
'
Public Function GetTestTableCount() As Integer
'
Dim oSQLConn As SqlConnection
Dim oSQLCmd As SqlCommand
Dim intResult As Integer = 0
'
oSQLConn = New
SqlConnection(ConfigurationManager.ConnectionStrin gs("SiteDB").ToString)
oSQLConn.Open()
'
oSQLCmd = New SqlCommand
oSQLCmd.Connection = oSQLConn
oSQLCmd.CommandType = CommandType.StoredProcedure
oSQLCmd.CommandText = "usp_GetTestTableCount"
'
intResult = oSQLCmd.ExecuteScalar
'
oSQLConn.Close()
'
End Function
'
'
Public Function GetTestTable(ByVal startRowIndex As Integer, ByVal
maximumRows As Integer) As List(Of TestTableClass)
'
Dim oSQLConn As SqlConnection
Dim oSQLCmd As SqlCommand
Dim oSQLParam As SqlParameter
Dim oDR As SqlDataReader
Dim mTTC As TestTableClass
Dim mColl As List(Of TestTableClass) = New List(Of
TestTableClass)
Dim intResult As Integer = 0
'
oSQLConn = New
SqlConnection(ConfigurationManager.ConnectionStrin gs("SiteDB").ToString)
oSQLConn.Open()
'
oSQLCmd = New SqlCommand
oSQLCmd.Connection = oSQLConn
oSQLCmd.CommandType = CommandType.StoredProcedure
oSQLCmd.CommandText = "usp_GetTestTable"
'
oSQLParam = New SqlParameter
oSQLParam.SqlDbType = SqlDbType.Int
oSQLParam.Direction = ParameterDirection.Input
oSQLParam.ParameterName = "startRowIndex"
oSQLParam.Value = startRowIndex
oSQLCmd.Parameters.Add(oSQLParam)
'
oSQLParam = New SqlParameter
oSQLParam.SqlDbType = SqlDbType.Int
oSQLParam.Direction = ParameterDirection.Input
oSQLParam.ParameterName = "maximumRows"
oSQLParam.Value = maximumRows
oSQLCmd.Parameters.Add(oSQLParam)
'
oDR = oSQLCmd.ExecuteReader()
'
While oDR.Read
'
mTTC = New TestTableClass
mTTC.UniqueID = oDR.Item("UniqueID").ToString
mTTC.Name = oDR.Item("Name").ToString
mTTC.BirthDate = oDR.Item("BirthDate")
mTTC.Comment = oDR.Item("Comment").ToString
'
mColl.Add(mTTC)
'
End While
'
oSQLConn.Close()
'
Return mColl
'
End Function
'
'
End Class

And the "Default.aspx" page (which has nothing in it's code-behind) is
defined as follows:

<%@ Page Language="VB" AutoEventWireup="false"
CodeFile="Default.aspx.vb" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
TypeName="TestTableClass" SelectCountMethod="GetTestTableCount"
SelectMethod="GetTestTable" EnablePaging="True">
</asp:ObjectDataSource>
<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
AutoGenerateColumns="False"
DataSourceID="ObjectDataSource1">
<Columns>
<asp:BoundField DataField="UniqueID"
HeaderText="UniqueID" SortExpression="UniqueID" />
<asp:BoundField DataField="BirthDate"
HeaderText="BirthDate" SortExpression="BirthDate" />
<asp:BoundField DataField="Name" HeaderText="Name"
SortExpression="Name" />
<asp:BoundField DataField="Comment"
HeaderText="Comment" SortExpression="Comment" />
</Columns>
</asp:GridView>
</div>
</form>
</body>
</html>

Nov 29 '06 #1
8 18046
Why not try:

1. Turn off the paging.

2. Change the type of data structure being returned, instead of List< >.
Start with a simple DataTable being returned.

And see if these produce different outcomes.

"Greg Lyles" <gr*******@mailinator.comwrote in message
news:md********************************@4ax.com...
Hi all,

I'm trying to develop an ASP.NET 2.0 website and am running into some
real problems with what I thought would be a relatively simple thing
to do.

In a nutshell, I'm stuck on trying to display data in a "GridView"
which is tied to an "ObjectDataSource".
In turn, this ObjectDatasource gets it's data from a strongly-typed
business object within my code.
I'm also trying to use custom paging, so my class has correctly
implemented methods to return the total count of records, and also the
method which retrieves the actual page of records is accepting two
parameters for the startRowIndex and maximumRows. I do NOT need any
sorting capability for this gridview, nor do I need any updating,
deleting, selecting functionality, either. I simply need to display
all the relevant records from the database (via my object), paged
(using SQL2005's ROW_NUMBER style paging).

I have this working beautifully when I use a strongly-typed dataset
for the ObjectDatasource's data, however, when I switch to using a
"business object", the Gridview doesn't seem to want to display any
data.

I can step through my code, and confirm that I am retrieving some
records from the database, which is then "returned" from the
"selectmethod" function call as a Generic List (ie. List(of T)).

Below, I've pasted some code that highlights my problem (I re-did the
code to focus on this one problem - in my real code, my DAL and BLL
are separate, whereas here they're in the same class, just for
brevity's sake). If your interested, you can download the entire
zipped up webproject (about 580kb) from here:
http://putstuff.putfile.com/17957/6448935
Has anyone encountered this problem before?? Does anyone know what
I'm doing wrong?? (I'm convinved it's something really simple that
I'm missing).

Any/all replies are greatly appreciated.
Regards,
Greg

The database has one table, as follows:

CREATE TABLE [dbo].[TestTable] (
[UniqueID] [uniqueidentifier] NOT NULL ,
[Name] [varchar] (50) NOT NULL ,
[BirthDate] [datetime] NOT NULL ,
[Comment] [varchar] (100) NOT NULL
)


There's 2 stored procedures, as follows:

ALTER PROCEDURE dbo.usp_GetTestTable
(
@startRowIndex int,
@maximumRows int
)

AS

SELECT UniqueID, [Name], BirthDate, Comment
FROM

(SELECT UniqueID, [Name], BirthDate, Comment, ROW_NUMBER()
OVER(ORDER BY BirthDate) AS RowNum
FROM TestTable
) AS TestTableList
WHERE RowNum BETWEEN @startRowIndex AND (@startRowIndex +
@maximumRows) - 1
and:

ALTER PROCEDURE dbo.usp_GetTestTableCount

AS

SELECT
COUNT(*)
FROM
TestTable


The "custom class" is defined as follows:

Imports Microsoft.VisualBasic
Imports System.Collections.Generic
Imports system.data
Imports System.Data.Sql
Imports system.Data.SqlClient

'
'
'
Public Class TestTableClass
'
'
Private m_UniqueID As String = ""
Private m_Name As String = ""
Private m_BirthDate As DateTime = Nothing
Private m_Comment As String = ""
'
'
Public Property UniqueID() As String
Get
Return m_UniqueID
End Get
Set(ByVal value As String)
m_UniqueID = value
End Set
End Property
'
Public Property Name() As String
Get
Return m_Name
End Get
Set(ByVal value As String)
m_Name = value
End Set
End Property
'
Public Property BirthDate() As DateTime
Get
Return m_BirthDate
End Get
Set(ByVal value As DateTime)
m_BirthDate = value
End Set
End Property
'
Public Property Comment() As String
Get
Return m_Comment
End Get
Set(ByVal value As String)
m_Comment = value
End Set
End Property
'
'
'
Public Function GetTestTableCount() As Integer
'
Dim oSQLConn As SqlConnection
Dim oSQLCmd As SqlCommand
Dim intResult As Integer = 0
'
oSQLConn = New
SqlConnection(ConfigurationManager.ConnectionStrin gs("SiteDB").ToString)
oSQLConn.Open()
'
oSQLCmd = New SqlCommand
oSQLCmd.Connection = oSQLConn
oSQLCmd.CommandType = CommandType.StoredProcedure
oSQLCmd.CommandText = "usp_GetTestTableCount"
'
intResult = oSQLCmd.ExecuteScalar
'
oSQLConn.Close()
'
End Function
'
'
Public Function GetTestTable(ByVal startRowIndex As Integer, ByVal
maximumRows As Integer) As List(Of TestTableClass)
'
Dim oSQLConn As SqlConnection
Dim oSQLCmd As SqlCommand
Dim oSQLParam As SqlParameter
Dim oDR As SqlDataReader
Dim mTTC As TestTableClass
Dim mColl As List(Of TestTableClass) = New List(Of
TestTableClass)
Dim intResult As Integer = 0
'
oSQLConn = New
SqlConnection(ConfigurationManager.ConnectionStrin gs("SiteDB").ToString)
oSQLConn.Open()
'
oSQLCmd = New SqlCommand
oSQLCmd.Connection = oSQLConn
oSQLCmd.CommandType = CommandType.StoredProcedure
oSQLCmd.CommandText = "usp_GetTestTable"
'
oSQLParam = New SqlParameter
oSQLParam.SqlDbType = SqlDbType.Int
oSQLParam.Direction = ParameterDirection.Input
oSQLParam.ParameterName = "startRowIndex"
oSQLParam.Value = startRowIndex
oSQLCmd.Parameters.Add(oSQLParam)
'
oSQLParam = New SqlParameter
oSQLParam.SqlDbType = SqlDbType.Int
oSQLParam.Direction = ParameterDirection.Input
oSQLParam.ParameterName = "maximumRows"
oSQLParam.Value = maximumRows
oSQLCmd.Parameters.Add(oSQLParam)
'
oDR = oSQLCmd.ExecuteReader()
'
While oDR.Read
'
mTTC = New TestTableClass
mTTC.UniqueID = oDR.Item("UniqueID").ToString
mTTC.Name = oDR.Item("Name").ToString
mTTC.BirthDate = oDR.Item("BirthDate")
mTTC.Comment = oDR.Item("Comment").ToString
'
mColl.Add(mTTC)
'
End While
'
oSQLConn.Close()
'
Return mColl
'
End Function
'
'
End Class

And the "Default.aspx" page (which has nothing in it's code-behind) is
defined as follows:

<%@ Page Language="VB" AutoEventWireup="false"
CodeFile="Default.aspx.vb" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
TypeName="TestTableClass" SelectCountMethod="GetTestTableCount"
SelectMethod="GetTestTable" EnablePaging="True">
</asp:ObjectDataSource>
<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
AutoGenerateColumns="False"
DataSourceID="ObjectDataSource1">
<Columns>
<asp:BoundField DataField="UniqueID"
HeaderText="UniqueID" SortExpression="UniqueID" />
<asp:BoundField DataField="BirthDate"
HeaderText="BirthDate" SortExpression="BirthDate" />
<asp:BoundField DataField="Name" HeaderText="Name"
SortExpression="Name" />
<asp:BoundField DataField="Comment"
HeaderText="Comment" SortExpression="Comment" />
</Columns>
</asp:GridView>
</div>
</form>
</body>
</html>

Nov 30 '06 #2
Hi Kevin,

Thanks for replying.

I have tried your first suggestion regarding turning off paging, and I
now seem to be able to get the GridView to display the records.

I did this by turning off both the "Enable Paging" property on the
Gridview control, and also turning off the "Enable Paging" property on
the ObjectDataSource. I had created a "GetTestTable" overload method
that took no parameters and just returned the complete table's worth
of data.

I was even able to turn the "Enable Paging" property of the
ObjectDataSource control back ON (which would then utilise the
GetTestTable method that takes the startRow and maximumRows
parameters) - I stepped through this function call and saw that
ASP.NET was passing in 0 (zero) for both the startRow and maximumRows
parameters (presumably because the "Enable Paging" property of the
Gridview control was still switched off). I was able to change these
values "in place" and watch the function run, and return the first 10
records from the table. These records would then be displayed within
the Gridview control (albeit without the "paging" options being
displayed).

So, it seems that the problem manifests itself when the "Enable
Paging" property of the GridView control is turned on, since the
paging that is happening within the ObjectDataSource seems to be
working correctly.

I have not tried your second suggestion (regarding returning a
DataTable rather then a generic list) since after trying the first
suggestion, the Gridview happily displayed my records.

Do you have any other suggestions as to what may cause the Gridview to
not display any records, even though the ObjectDatasource is correctly
returning records to be displayed ????

Thanks in advance.
Regards,
Greg.
On Thu, 30 Nov 2006 15:07:02 +1100, "Kevin Frey"
<ke**********@hotmail.comwrote:
>Why not try:

1. Turn off the paging.

2. Change the type of data structure being returned, instead of List< >.
Start with a simple DataTable being returned.

And see if these produce different outcomes.

"Greg Lyles" <gr*******@mailinator.comwrote in message
news:md********************************@4ax.com.. .
>Hi all,

I'm trying to develop an ASP.NET 2.0 website and am running into some
real problems with what I thought would be a relatively simple thing
to do.

In a nutshell, I'm stuck on trying to display data in a "GridView"
which is tied to an "ObjectDataSource".
In turn, this ObjectDatasource gets it's data from a strongly-typed
business object within my code.
[Snip!]
Nov 30 '06 #3
Are you setting the PageSize in the GridView? This is the only simple thing
that comes to mind (and I don't have much experience with ObjectDataSource).

"Greg Lyles" <gr*******@mailinator.comwrote in message
news:j0********************************@4ax.com...
Hi Kevin,

Thanks for replying.

I have tried your first suggestion regarding turning off paging, and I
now seem to be able to get the GridView to display the records.

I did this by turning off both the "Enable Paging" property on the
Gridview control, and also turning off the "Enable Paging" property on
the ObjectDataSource. I had created a "GetTestTable" overload method
that took no parameters and just returned the complete table's worth
of data.

I was even able to turn the "Enable Paging" property of the
ObjectDataSource control back ON (which would then utilise the
GetTestTable method that takes the startRow and maximumRows
parameters) - I stepped through this function call and saw that
ASP.NET was passing in 0 (zero) for both the startRow and maximumRows
parameters (presumably because the "Enable Paging" property of the
Gridview control was still switched off). I was able to change these
values "in place" and watch the function run, and return the first 10
records from the table. These records would then be displayed within
the Gridview control (albeit without the "paging" options being
displayed).

So, it seems that the problem manifests itself when the "Enable
Paging" property of the GridView control is turned on, since the
paging that is happening within the ObjectDataSource seems to be
working correctly.

I have not tried your second suggestion (regarding returning a
DataTable rather then a generic list) since after trying the first
suggestion, the Gridview happily displayed my records.

Do you have any other suggestions as to what may cause the Gridview to
not display any records, even though the ObjectDatasource is correctly
returning records to be displayed ????

Thanks in advance.
Regards,
Greg.
On Thu, 30 Nov 2006 15:07:02 +1100, "Kevin Frey"
<ke**********@hotmail.comwrote:
>>Why not try:

1. Turn off the paging.

2. Change the type of data structure being returned, instead of List< >.
Start with a simple DataTable being returned.

And see if these produce different outcomes.

"Greg Lyles" <gr*******@mailinator.comwrote in message
news:md********************************@4ax.com. ..
>>Hi all,

I'm trying to develop an ASP.NET 2.0 website and am running into some
real problems with what I thought would be a relatively simple thing
to do.

In a nutshell, I'm stuck on trying to display data in a "GridView"
which is tied to an "ObjectDataSource".
In turn, this ObjectDatasource gets it's data from a strongly-typed
business object within my code.
[Snip!]

Dec 1 '06 #4
One other comment - have you setup a SelectCountMethod in the
ObjectDataSource and your data provider?

This may also have something to do with it - but admittedly this suggestion
is merely a guess.

"Greg Lyles" <gr*******@mailinator.comwrote in message
news:j0********************************@4ax.com...
Hi Kevin,

Thanks for replying.

I have tried your first suggestion regarding turning off paging, and I
now seem to be able to get the GridView to display the records.

I did this by turning off both the "Enable Paging" property on the
Gridview control, and also turning off the "Enable Paging" property on
the ObjectDataSource. I had created a "GetTestTable" overload method
that took no parameters and just returned the complete table's worth
of data.

I was even able to turn the "Enable Paging" property of the
ObjectDataSource control back ON (which would then utilise the
GetTestTable method that takes the startRow and maximumRows
parameters) - I stepped through this function call and saw that
ASP.NET was passing in 0 (zero) for both the startRow and maximumRows
parameters (presumably because the "Enable Paging" property of the
Gridview control was still switched off). I was able to change these
values "in place" and watch the function run, and return the first 10
records from the table. These records would then be displayed within
the Gridview control (albeit without the "paging" options being
displayed).

So, it seems that the problem manifests itself when the "Enable
Paging" property of the GridView control is turned on, since the
paging that is happening within the ObjectDataSource seems to be
working correctly.

I have not tried your second suggestion (regarding returning a
DataTable rather then a generic list) since after trying the first
suggestion, the Gridview happily displayed my records.

Do you have any other suggestions as to what may cause the Gridview to
not display any records, even though the ObjectDatasource is correctly
returning records to be displayed ????

Thanks in advance.
Regards,
Greg.
On Thu, 30 Nov 2006 15:07:02 +1100, "Kevin Frey"
<ke**********@hotmail.comwrote:
>>Why not try:

1. Turn off the paging.

2. Change the type of data structure being returned, instead of List< >.
Start with a simple DataTable being returned.

And see if these produce different outcomes.

"Greg Lyles" <gr*******@mailinator.comwrote in message
news:md********************************@4ax.com. ..
>>Hi all,

I'm trying to develop an ASP.NET 2.0 website and am running into some
real problems with what I thought would be a relatively simple thing
to do.

In a nutshell, I'm stuck on trying to display data in a "GridView"
which is tied to an "ObjectDataSource".
In turn, this ObjectDatasource gets it's data from a strongly-typed
business object within my code.
[Snip!]

Dec 1 '06 #5
Hi Kevin,

I'm not explicitly setting the PageSize of the Gridview, just simply
using it's default value of 10. This is working correctly in that the
method call to the "SelectMethod" correctly returns only the first 10
rows from my database table.

As for the "SelectCountMethod", yes, I also have that defined within
the properties of the ObjectDatasource, and can step through my code
and verify that the runtime is indeed calling this method and getting
back the total count of records (13 in this case).

One thing I've noticed is that the "SelectCountMethod" is fired AFTER
the "SelectMethod".

Thanks for your time so far, Kevin, but I'm not really any further
forward with this. It's so frustrating since I thought this would be
a really simple thing to achieve, and I'm sure I'm just missing
something really simple, but don't know what that is.

Any other thoughts or suggestions on what's going wrong?
Anyone?
Regards,
Greg.

On Fri, 1 Dec 2006 12:13:21 +1100, "Kevin Frey"
<ke**********@hotmail.comwrote:
>Are you setting the PageSize in the GridView? This is the only simple thing
that comes to mind (and I don't have much experience with ObjectDataSource).
>One other comment - have you setup a SelectCountMethod in the
ObjectDataSource and your data provider?

This may also have something to do with it - but admittedly this suggestion
is merely a guess.

"Greg Lyles" <gr*******@mailinator.comwrote in message
news:j0********************************@4ax.com.. .
>Hi Kevin,

Thanks for replying.
[SNIP!]
Dec 1 '06 #6

After much head-bashing, I finally found the problem in the simple
test code that I posted, and the problem was all me.

Look at this function:
Public Function GetTestTableCount() As Integer
'
Dim oSQLConn As SqlConnection
Dim oSQLCmd As SqlCommand
Dim intResult As Integer = 0
'
oSQLConn = New
SqlConnection(ConfigurationManager.ConnectionStrin gs("SiteDB").ToString)
oSQLConn.Open()
'
oSQLCmd = New SqlCommand
oSQLCmd.Connection = oSQLConn
oSQLCmd.CommandType = CommandType.StoredProcedure
oSQLCmd.CommandText = "usp_GetTestTableCount"
'
intResult = oSQLCmd.ExecuteScalar
'
oSQLConn.Close()
'
End Function
Notice how it's supposed to return an Integer value with the total
count of the records in the database?

Notice how I'm getting this value, storing it in a private variable
that's local to this procedure, and then NEVER ACTUALLY RETURNING A
VALUE FROM THE PROCEDURE!!!!

Doh! [/Slaps forehead]

So, it's my bad...Sorry..

HOWEVER, this was just in the sample code that I posted. In my real
application, I WAS correctly returning a value from the
"SelectCountMethod", HOWEVER, I noticed that I'd declared the return
value to be of type Long rather than Integer. Integer is the correct
return type (as per the MSDN documentation - a small fact I'd
initially overlooked) - but no errors are thrown if you (incorrectly)
use a Long, even with "Option Strict" set to True. !!

Since the actual value being returned ARE within the range of an
Integer, I'd have thought that they would be implicitly cast from
Longs down to Integers, however, this appears not to be the case. At
least, the Gridview will refuse to display any data if the return
value from the "SelectCountMethod" is a Long rather than an Integer
type.

So, it was THIS small bug/error that caused my Gridview to display no
data.

Just thought I'd share this with everyone in case someone else
stumbles onto the same problem I had.
-Greg.
On Fri, 01 Dec 2006 09:30:06 +0000, Greg Lyles
<gr*******@mailinator.comwrote:
>Hi Kevin,

I'm not explicitly setting the PageSize of the Gridview, just simply
using it's default value of 10. This is working correctly in that the
method call to the "SelectMethod" correctly returns only the first 10
rows from my database table.

As for the "SelectCountMethod", yes, I also have that defined within
the properties of the ObjectDatasource, and can step through my code
and verify that the runtime is indeed calling this method and getting
back the total count of records (13 in this case).

One thing I've noticed is that the "SelectCountMethod" is fired AFTER
the "SelectMethod".

Thanks for your time so far, Kevin, but I'm not really any further
forward with this. It's so frustrating since I thought this would be
a really simple thing to achieve, and I'm sure I'm just missing
something really simple, but don't know what that is.

Any other thoughts or suggestions on what's going wrong?
Anyone?
Regards,
Greg.

On Fri, 1 Dec 2006 12:13:21 +1100, "Kevin Frey"
<ke**********@hotmail.comwrote:
>>Are you setting the PageSize in the GridView? This is the only simple thing
that comes to mind (and I don't have much experience with ObjectDataSource).
>>One other comment - have you setup a SelectCountMethod in the
ObjectDataSource and your data provider?

This may also have something to do with it - but admittedly this suggestion
is merely a guess.

"Greg Lyles" <gr*******@mailinator.comwrote in message
news:j0********************************@4ax.com. ..
>>Hi Kevin,

Thanks for replying.
[SNIP!]
Dec 2 '06 #7
Because the SelectCountMethod is presumably being called via some kind of
Reflection mechanism, I'm presuming that the mismatch in return value
results in the outcome that you describe.

Sorry I couldn't get you to the finish line, but at least you got there by
yourself in the end ;-)

"Greg Lyles" <gr*******@mailinator.comwrote in message
news:en********************************@4ax.com...
>
After much head-bashing, I finally found the problem in the simple
test code that I posted, and the problem was all me.

Look at this function:
Public Function GetTestTableCount() As Integer
'
Dim oSQLConn As SqlConnection
Dim oSQLCmd As SqlCommand
Dim intResult As Integer = 0
'
oSQLConn = New
SqlConnection(ConfigurationManager.ConnectionStrin gs("SiteDB").ToString)
oSQLConn.Open()
'
oSQLCmd = New SqlCommand
oSQLCmd.Connection = oSQLConn
oSQLCmd.CommandType = CommandType.StoredProcedure
oSQLCmd.CommandText = "usp_GetTestTableCount"
'
intResult = oSQLCmd.ExecuteScalar
'
oSQLConn.Close()
'
End Function
Notice how it's supposed to return an Integer value with the total
count of the records in the database?

Notice how I'm getting this value, storing it in a private variable
that's local to this procedure, and then NEVER ACTUALLY RETURNING A
VALUE FROM THE PROCEDURE!!!!

Doh! [/Slaps forehead]

So, it's my bad...Sorry..

HOWEVER, this was just in the sample code that I posted. In my real
application, I WAS correctly returning a value from the
"SelectCountMethod", HOWEVER, I noticed that I'd declared the return
value to be of type Long rather than Integer. Integer is the correct
return type (as per the MSDN documentation - a small fact I'd
initially overlooked) - but no errors are thrown if you (incorrectly)
use a Long, even with "Option Strict" set to True. !!

Since the actual value being returned ARE within the range of an
Integer, I'd have thought that they would be implicitly cast from
Longs down to Integers, however, this appears not to be the case. At
least, the Gridview will refuse to display any data if the return
value from the "SelectCountMethod" is a Long rather than an Integer
type.

So, it was THIS small bug/error that caused my Gridview to display no
data.

Just thought I'd share this with everyone in case someone else
stumbles onto the same problem I had.
-Greg.
On Fri, 01 Dec 2006 09:30:06 +0000, Greg Lyles
<gr*******@mailinator.comwrote:
>>Hi Kevin,

I'm not explicitly setting the PageSize of the Gridview, just simply
using it's default value of 10. This is working correctly in that the
method call to the "SelectMethod" correctly returns only the first 10
rows from my database table.

As for the "SelectCountMethod", yes, I also have that defined within
the properties of the ObjectDatasource, and can step through my code
and verify that the runtime is indeed calling this method and getting
back the total count of records (13 in this case).

One thing I've noticed is that the "SelectCountMethod" is fired AFTER
the "SelectMethod".

Thanks for your time so far, Kevin, but I'm not really any further
forward with this. It's so frustrating since I thought this would be
a really simple thing to achieve, and I'm sure I'm just missing
something really simple, but don't know what that is.

Any other thoughts or suggestions on what's going wrong?
Anyone?
Regards,
Greg.

On Fri, 1 Dec 2006 12:13:21 +1100, "Kevin Frey"
<ke**********@hotmail.comwrote:
>>>Are you setting the PageSize in the GridView? This is the only simple
thing
that comes to mind (and I don't have much experience with
ObjectDataSource).
>>>One other comment - have you setup a SelectCountMethod in the
ObjectDataSource and your data provider?

This may also have something to do with it - but admittedly this
suggestion
is merely a guess.

"Greg Lyles" <gr*******@mailinator.comwrote in message
news:j0********************************@4ax.com ...
Hi Kevin,

Thanks for replying.
[SNIP!]

Dec 3 '06 #8
On Mon, 4 Dec 2006 10:13:53 +1100, "Kevin Frey"
<ke**********@hotmail.comwrote:

Hi Kevin.
>Because the SelectCountMethod is presumably being called via some kind of
Reflection mechanism, I'm presuming that the mismatch in return value
results in the outcome that you describe.
Yes. The "SelectCount" method is indeed called via the runtime's own
reflection, and it seems not to like Longs (for this method, at
least). The Gridview will simply display no data (or your "No data"
caption, if you've got one set).

What was most frustrating, of course, is that no error was thrown when
this occured. This made "step-thru" debugging exceptionally
difficult. I could see my function getting the value correctly, and
returning it correctly from the function. Of course, stepping into
the next line of code after this doesn't work, since the next thing to
execute is the runtime's own reflection mechanism to invoke the call
to the "SelectCount" method, something which cannot be "stepped-thru".

Had an error been thrown due to the incorrect return type from the
"SelectCount" method, I'd have nailed this problem in 10 seconds flat!
:)

It seems that the runtime was receiving a valid "value", but not
within the correct, explicitly expressed type, thus the reflection
mechanism was probably passing a "count" value of zero through to the
Gridview control, hence no data.
>
Sorry I couldn't get you to the finish line, but at least you got there by
yourself in the end ;-)
I'm still very grateful for your input, Kevin. You certainly pointed
me in the right direction (in removing the paging, thus being able to
isolate just *where* the problem was occuring), so thanks very much.

This seemed to be one of those little idiosyncracies of .NET (as any
development platform has) that can easily confuse and cause much
hair-pulling, since the problem a) doesn't throw an error and b) is
hidden deep within the bowels of the framework/runtime itself.

Just hoping that, if someone else has the same problem I did, they can
find this thread, since I know how frustrating this one was!
Thanks again.

Regards,
Greg.

>
"Greg Lyles" <gr*******@mailinator.comwrote in message
news:en********************************@4ax.com.. .
>>
After much head-bashing, I finally found the problem in the simple
test code that I posted, and the problem was all me.

[SNIP!]
Dec 4 '06 #9

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

Similar topics

3
by: vinayak | last post by:
Hi I am displaying data in Datagrid in ASP.NET with Edit/Update functionality for each row. On the same page I have 2 Button controls which submits the request to server. These button controls...
3
by: mosscliffe | last post by:
I have a gridview and in the GridView1_SelectedIndexChanged routine I am attempting to get at the data in the row I have done it successfully with cells 'Access the contents of a field in a...
1
by: slayerx | last post by:
Quote: Originally Posted by comteck As far as I know, a report is just that.. a means of displaying data. I don't believe it is possible to make a selection in a report. You can however, make a...
0
by: gr8beer | last post by:
The gridview rebinds data before the RowCommand or RowEditing events fire. So, if a new record is added to the underlying datasource that changes the index of the row you are trying to edit, you...
1
by: weird0 | last post by:
I have created a GridView and dynamically added data to it by creating a DataTable(as advised) and bound it with a reader. Then, assigned the DataSource of GridView to DataTable. But even that aint...
1
by: seadog | last post by:
Hi, I am having a problem displaying data in a textbox array. What I am trying to do is have 5 number enter 5 textboxes, starting from the first and working there way to the bottom textbox. What...
6
by: jaredciagar | last post by:
Hi Guys Can you help me please in my project, I have tblItemList in my SQL DB. I want to display all the data in my tblItemList in GridView control.... How Can I Do That in VB Script using VB.Net......
11
by: dba | last post by:
Have been displaying data from database using html for some time but just recently trying to display data back to "form". Can't find answer. <form method="post" action="<?php echo $PHP_SELF;?>">...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...

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.