473,516 Members | 3,399 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 18068
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
4891
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 are Web Control & not HTML control. One of these buttons whose title is Delete is added on the aspx page in design view & also I double clicked on...
3
3261
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 GRIDVIEW Dim joe As String = GridView1.SelectedRow.Cells(1).Text lbxDebug.Items.Insert(0, joe) but I thought I would try to access the data via the...
1
1664
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 selection from a combo box on a form, and then have this selection displayed on the report. comteck could you tell me how to do that
0
1270
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 get the wrong row displayed for editing. I am guessing same is true when deleting which is even worse, especially if you are not confirming on...
1
2746
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 working as alternatively assigned reader obj. to datasource of GridView. Here is the code for the aspx.cs page: ( The reader surely cootains...
1
2447
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 is happening is that the displaying of the data is not happening until the process is complete, I have tryed a for next loop, for x = 1 to 5,...
6
12946
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... Thank you... Please Help Me... Regards, Jared
11
2404
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;?>"> First Name:<input type="text" size="12" maxlength="12" name="Fname"><br > Last Name:<input type="text" size="12" maxlength="36" name="Lname"><br />...
0
7273
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7182
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7405
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7547
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5106
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4769
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3252
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
823
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
487
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.