Paging?

  • Thread starter Thread starter DaMan
  • Start date Start date
D

DaMan

Ok.. I followed simple code example in MSDN for simple paging of a datagrid,
but I get Error:

AllowCustomPaging must be true and VirtualItemCount must be set for a
DataGrid with ID DataGrid1 when AllowPaging is set to true and the selected
datasource does not implement ICollection.

Why,??? I can set AllowCustomPaging and get the data, but then paging
doesn't work??HUNH??
Heres my code:
SQLDB.Open()
SQLcmd.CommandType = CommandType.StoredProcedure
SQLcmd.CommandText = "dotnet_GetData"
SqlCommandBuilder.DeriveParameters(tmpSQL.SQLcmd)
SQLcmd.Parameters(1).Value = "%"
Dim myreader As SqlDataReader = SQLcmd.ExecuteReader
myreader.Read()
DataGrid1.DataSource = myreader
With DataGrid1
.AllowPaging = True
.PagerStyle.Mode = PagerMode.NumericPages
.PageSize = 15
.PagerStyle.PageButtonCount = 15
End With

do stuff

If Not Page.IsPostBack Then
DataGrid1.DataBind()

End If

Moving the With DataGrid1 block around doesn't help??? Please help??
Thanks...

KT
 
Hi DaMan,

DataReader can not be used as DataSource for DataGrid as it doesn't
implement Icollection Interface. For Default paging to work in DataGrid, it
has to use the Count property of Icollection Interface to get the total
number of rows in datasource. Since DataReader is not implement ICollection
interface you will get this error. This issue is actually by design.

The workaround is

1. Use DataSet, DataTable or DataView instead of DataReader for DataGrid
source .
or
2. Set Virtualitemcount of DataGrid to the count of rows in Datareader.

If there's anything unclear, please feel free to reply to the post.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
Back
Top