Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 28th, 2005, 05:13 AM
Authorized User
 
Join Date: Apr 2005
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
Default DataGrid Paging Problem

Hi, i have a datagrid to display the data retrieved from database using datareader. I set custom paging to false, it will give me the following error.

Server Error in '/e-library' Application.
--------------------------------------------------------------------------------

AllowCustomPaging must be true and VirtualItemCount must be set for a DataGrid with ID DgFaqs when AllowPaging is set to true and the selected datasource does not implement ICollection.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Web.HttpException: AllowCustomPaging must be true and VirtualItemCount must be set for a DataGrid with ID DgFaqs when AllowPaging is set to true and the selected datasource does not implement ICollection.

Source Error:


Line 50: dr = cmd.ExecuteReader
Line 51: DgFaqs.DataSource = dr
Line 52: DgFaqs.DataBind()
Line 53: con.Close()
Line 54: End Sub


Source File: c:\inetpub\wwwroot\e-library\Help.aspx.vb Line: 52

Stack Trace:


[HttpException (0x80004005): AllowCustomPaging must be true and VirtualItemCount must be set for a DataGrid with ID DgFaqs when AllowPaging is set to true and the selected datasource does not implement ICollection.]
   System.Web.UI.WebControls.DataGrid.CreateControlHi erarchy(Boolean useDataSource) +2068
   System.Web.UI.WebControls.BaseDataList.OnDataBindi ng(EventArgs e) +49
   System.Web.UI.WebControls.BaseDataList.DataBind() +23
   e_library.Help.BindGrid() in c:\inetpub\wwwroot\e-library\Help.aspx.vb:52
   e_library.Help.Page_Load(Object sender, EventArgs e) in c:\inetpub\wwwroot\e-library\Help.aspx.vb:31
   System.Web.UI.Control.OnLoad(EventArgs e) +67
   System.Web.UI.Control.LoadRecursive() +35
   System.Web.UI.Page.ProcessRequestMain() +750




--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:1.1.4322.2032; ASP.NET Version:1.1.4322.2032


But if I set custom paging to true, the data is displayed, but I cant navigate through the records.

Below are my coding:

Code:
 Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If Not IsPostBack Then
            BindGrid()
        End If
        btnLogout.Attributes.Add("onclick", "return confirm('Are you sure you want to exit E-Library System?');")
    End Sub

    Private Sub BindGrid()
        Dim a As New Common
        Dim con As New SqlConnection
        con = a.GetConnect()

        DgFaqs.Visible = True
        Dim cmd As New SqlCommand
        Dim dr As SqlDataReader

        cmd.CommandText = "select * from FAQs"
        cmd.CommandType = CommandType.Text
        cmd.Connection = con
        con.Open()

        dr = cmd.ExecuteReader
        DgFaqs.DataSource = dr
        DgFaqs.DataBind()
        con.Close()
    End Sub

    Private Sub DgFaqs_PageIndexChanged(ByVal sender As System.Object, ByVal e As System.Web.UI.WebControls.DataGridPageChangedEventArgs)
        DgFaqs.CurrentPageIndex = e.NewPageIndex
        BindGrid()
    End Sub
Can somebody point out what is the problem behind this? Thanks a lot!

Irene

 
Old June 28th, 2005, 05:50 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Hi there Irene,

The problem here is with the DataReader class. Because of the way this class is built, it can't provide information on what lies ahead in the data. It provides a one-shot access to a current row of data because it's maintain a direct, live connection to the data source. When you call the Read() method it hits the data source again and gets the next row. Think of the DataReader as a data conveyor belt. You get the data as it comes but you never know how much there will be. The point of all this is that the DataReader (just as the error you are getting states) does not implement ICollection. It is not a collection.

If you were to use a DataTable (in a DataSet) you would not get this error. A DataTable has a collection of rows that implements ICollection. Think of a DataTable as a big barrel of data. When you get it you know how much is in it.

The DataGrid control expects to use the ICollection interface so you need to use something that implements that. In most cases this means changing your use of DataReader to DataSet/DataTable. This will mean you'll need to use a DataAdapter along with the Command and Connection classes.

-Peter
 
Old June 28th, 2005, 06:17 AM
Authorized User
 
Join Date: Apr 2005
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Peter,

now I use dataset, & set custom paging to false. But even though the data is displayed,
the paging does not works. I set page size to 5 rows, even though I have 7 records,
it only allow me to view the first 5 records.

Is it I miss out something?

Irene

 
Old June 28th, 2005, 08:19 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

The "DgFaqs_PageIndexChanged" method is missing " Handles DgFaqs.PageIndexChanged"

-Peter
 
Old June 28th, 2005, 10:39 PM
Authorized User
 
Join Date: Jun 2005
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to naresh.net
Default

hi there,
u can write a stored procedure that counts the rows od the data in a table.
then use a function (say fun_countrows) in the coding part that returns the no. of rows of the data.
then use this function as VirtualItemCount=fun_countrows
this may solve the problem.

'''''''''stored procedure
ALTER PROCEDURE proc_name
    (
        @NumOfRow int = 0
    )
AS
    SET @NumOfRow = (select count(*) as NumOfRow from proc_name);

    RETURN @NumOfRow


 
Old April 23rd, 2006, 03:15 AM
Registered User
 
Join Date: Apr 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.GetFie ldType(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(setToChe ck.GetName(g)));

}


dataReaderTable.Rows.Add(dr);

}

return dataReaderTable.DefaultView;

}

catch

{

return null;

}




}

















Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem in Paging in Datagrid Rahul Gupta ASP.NET 1.0 and 1.1 Basics 0 December 16th, 2005 07:58 AM
DataGrid Paging Problem! zakaria ASP.NET 1.0 and 1.1 Basics 1 April 8th, 2005 06:12 PM
Problem in dataGrid Paging Baby_programmer ASP.NET 1.0 and 1.1 Professional 2 February 23rd, 2005 08:47 PM
Paging problem with datareader and datagrid alyeng2000 ASP.NET 1.0 and 1.1 Basics 4 September 9th, 2004 02:31 AM
DataGrid Paging Problem acyu0318 ASP.NET 1.0 and 1.1 Basics 2 March 2nd, 2004 12:05 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.