Gridview and paging doesn't work

C

Carlos Albert

Hi everybody,

I'm working with a gridview (4 bound columns and 1 template column, using
databind from codebehind). It works just fine, but I tried to add paging,
and when I click any paging button (next, last, or page #), it return this
error and I don't know what's wrong:

Source Error:

An unhandled exception was generated during the execution of the
current web request. Information regarding the origin and location of the
exception can be identified using the exception stack trace below.

Stack Trace:

[HttpException (0x80004005): The GridView 'GridView1' fired event
PageIndexChanging which wasn't handled.]
System.Web.UI.WebControls.GridView.OnPageIndexChanging(GridViewPageEventArgs
e) +1427299
System.Web.UI.WebControls.GridView.HandlePage(Int32 newPage) +83
System.Web.UI.WebControls.GridView.HandleEvent(EventArgs e, Boolean
causesValidation, String validationGroup) +488
System.Web.UI.WebControls.GridView.RaisePostBackEvent(String
eventArgument) +199
System.Web.UI.WebControls.GridView.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String
eventArgument) +7
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
sourceControl, String eventArgument) +11
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +174
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5102


Any idea?
 
T

tdavisjr

What kind of datasource are you binding to. IF you are binding to a
sqldatasource, then you should be able to do this wihout writing any
extra code. However, if you are binding to a custom object that returns
a collection, then, more work may have to be done.
 
C

Carlos Albert

Uhmmm... I'm binding it to a datatable obtained from an xml:

Dim ds As New Data.DataSet
Dim xml As String = library.H(x_parameter)
ds.ReadXml(New System.IO.StringReader(xml))
GridView1.DataSource = ds.Tables(0)
GridView1.DataBind()
ds.Dispose()

How do would you say I should do?
 
T

tdavisjr

Well, if you do it this way then to page and sort you may have to
handle the sort and page events on the gridview.
However, if you drag a objectdatasource and configure it to bind to
the xml file, then tell the gridview that is datasource is the
objectdatasource , and also enable paging and sorting on the gridview.
I think it will do this without you writing any code. Check out the
asp.net quickstart tutorials to see some examples
 
C

Carlos Albert

Uhmmm... already tried to do that but I obtained this error: "The data
source does not support server-side data paging."

One comment: the XML is not a file, is a function that RETURNS and xml to
pass data from one layer to another...
 
T

tdavisjr

Well. I would still use the objectdatasource, however, I would create
a class with one method that wrapps your function that returns xml,
however, I would take the xml and convert it to a dataset (i think
using, dataset.GetXml()) and return that to the objectdatasource. The
dataset should be able to sort and page.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top