An ASP.NET Blog
I work for Microsoft and help people and businesses make better use of technolgy to realize their full potential. The opinions mentioned herein are solely mine and do not reflect those of my employer.

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

Wednesday, May 25, 2005 12:35 PM

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


Feedback

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

Thanks for posting this.

Its just sorted my problem. 6/6/2005 11:32 AM | JE

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

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

8/23/2005 10:58 AM | kishore

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

Definate thanks! Saved me some research... 1/9/2006 2:24 PM | Ryan J

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

Thank u very much 2/1/2006 4:01 AM | morteza

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

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

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

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;

}




}

4/23/2006 5:44 AM | Baris ERGUN

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

Thanks a Lot 7/28/2006 8:31 AM | JOhn Rajesh

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

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

11/21/2006 5:46 AM | Manish

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

Thank you, saved me some research..... :-) 2/21/2008 6:36 AM | immy

Post a comment





 

Please add 2 and 5 and type the answer here: