Gridview not displaying data - please help!

G

Greg Lyles

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.ConnectionStrings("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.ConnectionStrings("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>
 
K

Kevin Frey

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 said:
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.ConnectionStrings("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.ConnectionStrings("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>
 
G

Greg Lyles

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.


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 said:
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!]
 
K

Kevin Frey

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 said:
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.


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 said:
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!]
 
K

Kevin Frey

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 said:
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.


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 said:
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!]
 
G

Greg Lyles

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.





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 said:
Hi Kevin,

Thanks for replying.
[SNIP!]
 
G

Greg Lyles

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


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.





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 said:
Hi Kevin,

Thanks for replying.
[SNIP!]
 
K

Kevin Frey

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 said:
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.ConnectionStrings("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.


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.





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.

Hi Kevin,

Thanks for replying.
[SNIP!]
 
B

Billy Biro

On Mon, 4 Dec 2006 10:13:53 +1100, "Kevin Frey"

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 said:
After much head-bashing, I finally found the problem in the simple
test code that I posted, and the problem was all me.

[SNIP!]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,754
Messages
2,569,528
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top