Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Datagrid Control > PageIndexChange in datagrid

Reply
Thread Tools

PageIndexChange in datagrid

 
 
pietaster
Guest
Posts: n/a
 
      02-17-2004
I have a datagrid that I need to allow paging. The datagrid only gets
loaded when !IsPostBack. If this is the case paging does not work. If
I load the datagrid IsPostBack then the paging works. Then the problem
would be that when paged the data will get loaded twice. Once from
Page_Load and once from datagrid_PageIndexChange. What should I
do?????

My paging event gets loaded in OnInt. AllowPaging and PageSize and
other things needed for paging are also loaded in OnInt.

Thanks.
pietaster
 
Reply With Quote
 
 
 
 
Renato Aloi
Guest
Posts: n/a
 
      02-17-2004
The default behavior of the datagrid's pagin' is:

Not IsPostBack (first time load)
- On Page load: DataBind the datagrid

IsPostBack (every other load)
- On Page load: Skips binding
- On Page Index change: Set the new page index and databind the datagrid

The best way to do this is combining not is postback with a routine to
databind the datagrid, like this:

' 1. {
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

If Not IsPostBack Then
Me.loadDataGrid()
End If

End Sub
' }

' 2. {
Private Sub DataGrid1_PageIndexChanged(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridPageChangedEvent Args) Handles
DataGrid1.PageIndexChanged

Me.DataGrid1.CurrentPageIndex = e.NewPageIndex
Me.loadDataGrid()

End Sub
' }

' 3. {
Private Sub loadDataGrid()

Me.DataGrid1.DataSource = whateverDataSource
Me.DataGrid1.DataBind()

End Sub
' }

[]s
Graccs

"pietaster" <(E-Mail Removed)> escreveu na mensagem
news:(E-Mail Removed) om...
> I have a datagrid that I need to allow paging. The datagrid only gets
> loaded when !IsPostBack. If this is the case paging does not work. If
> I load the datagrid IsPostBack then the paging works. Then the problem
> would be that when paged the data will get loaded twice. Once from
> Page_Load and once from datagrid_PageIndexChange. What should I
> do?????
>
> My paging event gets loaded in OnInt. AllowPaging and PageSize and
> other things needed for paging are also loaded in OnInt.
>
> Thanks.
> pietaster



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
DataTable with 15 records -> GridView PageIndexChange doesn't display the next 5 record Fabio Mastria ASP .Net 1 04-03-2008 09:12 AM
SortCommand and PageIndexChange event not firing sa siva via .NET 247 ASP .Net Datagrid Control 2 05-05-2005 03:07 PM
datagrid in datagrid BK Kim ASP .Net 1 03-02-2004 06:34 AM
Call Datagrid Command column outside datagrid Dave ASP .Net 0 11-20-2003 11:11 AM
To all Gurus: How can I edit/update a DataGrid in a DataGrid (nested DataGrid)? Possible? Andreas Klemt ASP .Net Datagrid Control 0 10-08-2003 01:19 AM



Advertisments