You may receive the error "AllowCustomPaging must be true and VirtualItemCount must be set for a DataGrid with ID DataGrid1 when..."

You may receive the 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." while attempting to bind a DataGrid to a DataReader and also setting the Datagrid's AllowPaging property to True.

The error occurs since you are binding a DataReader to the DataGrid. The DataReader offers a Forward Only - Read Only access to the Data that is being retrieved from the DataSource.

Since Paging would require the ResultSet to be accesible Forward as well as Reverse (To implement the Previous / Next set of records), the DataReader cannot help in this scenario.

Even if you set the AllowCustomPaging=true, though the error disappears, you will only be able to see the first set of records and will be unable to implement the built-in paging functionality provided by the DataGrid.

The resolution for the same is to use a DataSet which offers an In memory representation of Data so that you can navigate back and forth the resultset as well as do modifications to the result set. This way you can use the built-in paging functionality in your DataGrid.

However, if you want to only use a DataReader, then you need to store all the values of the DataReader in an array etc., and write custom paging functionality to implement paging.

Cheers and Happy Programming !!!

Print | posted on Wednesday, May 25, 2005 12:35 PM

Comments on this post

# re: You may receive the error "AllowCustomPaging must be true and VirtualItemCount must be set for a DataGrid with ID DataGrid1 when..."

Requesting Gravatar...
Thanks for posting this.

Its just sorted my problem.
Left by JE on Jun 06, 2005 11:32 AM

# re: You may receive the error "AllowCustomPaging must be true and VirtualItemCount must be set for a DataGrid with ID DataGrid1 when..."

Requesting Gravatar...
Thankyou very much for the "anwer to the point".

Left by kishore on Aug 23, 2005 10:58 AM

# re: You may receive the error "AllowCustomPaging must be true and VirtualItemCount must be set for a DataGrid with ID DataGrid1 when..."

Requesting Gravatar...
Definate thanks! Saved me some research...
Left by Ryan J on Jan 09, 2006 2:24 PM

# re: You may receive the error "AllowCustomPaging must be true and VirtualItemCount must be set for a DataGrid with ID DataGrid1 when..."

Requesting Gravatar...
Thank u very much
Left by morteza on Feb 01, 2006 4:01 AM

# re: You may receive the error "AllowCustomPaging must be true and VirtualItemCount must be set for a DataGrid with ID DataGrid1 when..."

Requesting Gravatar...
Thanks!!For helpfull guys like u , Programming is so interesting!!
Left by Subhajit on Feb 07, 2006 4:23 AM

# re: You may receive the error "AllowCustomPaging must be true and VirtualItemCount must be set for a DataGrid with ID DataGrid1 when..."

Requesting Gravatar...
Hello

The DataReaders read one-way data As I undesrtand you dynamically bind your Oracle Database to your Datagird. Try to convert oracleDataReader to DataView. DataViews can be red 2 way and they are Compatible with AllowPaging=true

I have recently sent a Control to Asp.Net I think it is in the proccessing stage that Control converts OdbcDataReader to DataView below is the open code for you to give you an idea. You must apply the same logic to your Oracle Reader

Good Luck,

Baris ERGUN

www.thecoreopsis.com

public static DataView ConvertToDataView(OdbcDataReader setToCheck, string tableName)

{


DataTable dataReaderTable = new DataTable(tableName);


try

{

for(int h=0;h<setToCheck.FieldCount;h++)

{

DataColumn temp = new DataColumn(setToCheck.GetName(h),setToCheck.GetFieldType(h));

dataReaderTable.Columns.Add(temp);

}


while(setToCheck.Read())

{


DataRow dr = dataReaderTable.NewRow();

for(int g=0;g<setToCheck.FieldCount;g++)

{

dr[g] = setToCheck.GetValue(setToCheck.GetOrdinal(setToCheck.GetName(g)));

}


dataReaderTable.Rows.Add(dr);

}

return dataReaderTable.DefaultView;

}

catch

{

return null;

}




}

Left by Baris ERGUN on Apr 23, 2006 5:44 AM

# re: You may receive the error "AllowCustomPaging must be true and VirtualItemCount must be set for a DataGrid with ID DataGrid1 when..."

Requesting Gravatar...
Thanks a Lot
Left by JOhn Rajesh on Jul 28, 2006 8:31 AM

# re: You may receive the error "AllowCustomPaging must be true and VirtualItemCount must be set for a DataGrid with ID DataGrid1 when..."

Requesting Gravatar...
greate code thanks for this this is more helpful for me.

Left by Manish on Nov 21, 2006 5:46 AM

# re: You may receive the error "AllowCustomPaging must be true and VirtualItemCount must be set for a DataGrid with ID DataGrid1

Requesting Gravatar...
Thank you, saved me some research..... :-)
Left by immy on Feb 21, 2008 6:36 AM

# re: You may receive the error "AllowCustomPaging must be true and VirtualItemCount must be set for a DataGrid with ID DataGrid1

Requesting Gravatar...
thanks you very-2 much
Left by Nilesh on Aug 10, 2009 3:15 AM

# Design

Requesting Gravatar...
lovely post and great code:-)
office refurbishment
Left by rooby on Jan 06, 2011 9:17 PM

Your comment:

 (will show your gravatar)