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 !!!

posted @ Wednesday, May 25, 2005 12:35 PM

Print

Comments on this entry:

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

Left by JE at 6/6/2005 11:32 AM
Gravatar
Thanks for posting this.

Its just sorted my problem.

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

Left by kishore at 8/23/2005 10:58 AM
Gravatar
Thankyou very much for the "anwer to the point".

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

Left by Ryan J at 1/9/2006 2:24 PM
Gravatar
Definate thanks! Saved me some research...

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

Left by morteza at 2/1/2006 4:01 AM
Gravatar
Thank u very much

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

Left by Subhajit at 2/7/2006 4:23 AM
Gravatar
Thanks!!For helpfull guys like u , Programming is so interesting!!

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

Left by Baris ERGUN at 4/23/2006 5:44 AM
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;

}




}

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

Left by JOhn Rajesh at 7/28/2006 8:31 AM
Gravatar
Thanks a Lot

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

Left by Manish at 11/21/2006 5:46 AM
Gravatar
greate code thanks for this this is more helpful for me.

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

Left by immy at 2/21/2008 6:36 AM
Gravatar
Thank you, saved me some research..... :-)

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

Left by Nilesh at 8/10/2009 3:15 AM
Gravatar
thanks you very-2 much

Your comment:



 (will not be displayed)


 
 
 
 
 

Live Comment Preview:

 
«November»
SunMonTueWedThuFriSat
25262728293031
1234567
891011121314
15161718192021
22232425262728
293012345