| Author |
Message |
jrmcdona
Guest
|
Posted:
Tue Jan 11, 2005 4:17 am Post subject:
datagrid sorting/paging in a web part |
|
|
Does anybody know where i can locate some sample code for doing datagrid
sorting or paging within a web part. In my previous work, i have done this
via a web application using view state. However, a web part does not have
view state and I cannot seem to get this working correctly.
thanks! |
|
| Back to top |
|
 |
Amar Galla
Guest
|
Posted:
Tue Jan 11, 2005 4:03 pm Post subject:
Re: datagrid sorting/paging in a web part |
|
|
Hi,
First of all, a web part would have viewstate. So you can very well store
any intermediate data you need on the viewstate.
For doing a paging on a datagrid in a web part, you just have to set the
pagesize and allowpaging properties. Check the small code snippet below.
grid.AllowPaging = true;
grid.PageSize = 5;
grid.PageIndexChanged +=new
DataGridPageChangedEventHandler(grid_PageIndexChanged);
You can write the paging logic or associate a new page in the
pageindexchanged event as grid.CurrentPageIndex = e.NewPageIndex; and bind
the grid to the datasource.
Hope this helps.
Regards,
Amar Galla
http://www.dotnetjunkies.com/weblog/amar
"jrmcdona" <jmc_1776@hotmail.com> wrote in message
news:26625E41-97A8-40DE-83B1-430F033879ED@microsoft.com...
| Quote: | Does anybody know where i can locate some sample code for doing datagrid
sorting or paging within a web part. In my previous work, i have done this
via a web application using view state. However, a web part does not have
view state and I cannot seem to get this working correctly.
thanks!
|
|
|
| Back to top |
|
 |
jrmcdona
Guest
|
Posted:
Wed Jan 12, 2005 1:35 am Post subject:
Re: datagrid sorting/paging in a web part |
|
|
Awesome, thanks. I got it working. I thought i read that there was no
viewstate.
Jordan
"Amar Galla" wrote:
| Quote: | Hi,
First of all, a web part would have viewstate. So you can very well store
any intermediate data you need on the viewstate.
For doing a paging on a datagrid in a web part, you just have to set the
pagesize and allowpaging properties. Check the small code snippet below.
grid.AllowPaging = true;
grid.PageSize = 5;
grid.PageIndexChanged +=new
DataGridPageChangedEventHandler(grid_PageIndexChanged);
You can write the paging logic or associate a new page in the
pageindexchanged event as grid.CurrentPageIndex = e.NewPageIndex; and bind
the grid to the datasource.
Hope this helps.
Regards,
Amar Galla
http://www.dotnetjunkies.com/weblog/amar
"jrmcdona" <jmc_1776@hotmail.com> wrote in message
news:26625E41-97A8-40DE-83B1-430F033879ED@microsoft.com...
Does anybody know where i can locate some sample code for doing datagrid
sorting or paging within a web part. In my previous work, i have done this
via a web application using view state. However, a web part does not have
view state and I cannot seem to get this working correctly.
thanks!
|
|
|
| Back to top |
|
 |
Dave W.
Guest
|
Posted:
Wed Jan 12, 2005 2:39 am Post subject:
Re: datagrid sorting/paging in a web part |
|
|
I have this in my code now. And it is still now working. It seems that the
pageindexedchanged event fires after the page refreshes and the
createchildcontrols runs.
I build the grid in createchildcontrols, get the datasource, then bind. I
click on the page arrow and the page refreshed and CCC executes, and the
pageindexedchanged fires and the page doesn't change.
Is there an order I need to do this in? Does it matter that my datasource is
from XML. Thanks. Dave
"Amar Galla" wrote:
| Quote: | Hi,
First of all, a web part would have viewstate. So you can very well store
any intermediate data you need on the viewstate.
For doing a paging on a datagrid in a web part, you just have to set the
pagesize and allowpaging properties. Check the small code snippet below.
grid.AllowPaging = true;
grid.PageSize = 5;
grid.PageIndexChanged +=new
DataGridPageChangedEventHandler(grid_PageIndexChanged);
You can write the paging logic or associate a new page in the
pageindexchanged event as grid.CurrentPageIndex = e.NewPageIndex; and bind
the grid to the datasource.
Hope this helps.
Regards,
Amar Galla
http://www.dotnetjunkies.com/weblog/amar
"jrmcdona" <jmc_1776@hotmail.com> wrote in message
news:26625E41-97A8-40DE-83B1-430F033879ED@microsoft.com...
Does anybody know where i can locate some sample code for doing datagrid
sorting or paging within a web part. In my previous work, i have done this
via a web application using view state. However, a web part does not have
view state and I cannot seem to get this working correctly.
thanks!
|
|
|
| Back to top |
|
 |
landeiro@gmail.com
Guest
|
Posted:
Wed Jan 12, 2005 3:32 pm Post subject:
Re: datagrid sorting/paging in a web part |
|
|
Make sure you are binding de data after you change de currentIndex to
the new one.
Are you adding the DataGrid to the controls in the CreateChildControls?
-> this.Controls.Add(myDataGrid)
If you dont do this the event will not be fired. |
|
| Back to top |
|
 |
Amar Galla
Guest
|
Posted:
Wed Jan 12, 2005 4:01 pm Post subject:
Re: datagrid sorting/paging in a web part |
|
|
Cool. After you set the new page index in the pageindexchanged event
handler, you will have to rebind the datagrid to a datasource. That should
make it show the updated data.
Hope this helps.
Regards,
Amar Galla
http://www.dotnetjunkies.com/weblog/amar/
"Dave W." <llowevad@gmail.com> wrote in message
news:1DA7F0FE-DC11-42D5-B082-6A5984DC83FD@microsoft.com...
| Quote: | I have this in my code now. And it is still now working. It seems that the
pageindexedchanged event fires after the page refreshes and the
createchildcontrols runs.
I build the grid in createchildcontrols, get the datasource, then bind. I
click on the page arrow and the page refreshed and CCC executes, and the
pageindexedchanged fires and the page doesn't change.
Is there an order I need to do this in? Does it matter that my datasource
is
from XML. Thanks. Dave
"Amar Galla" wrote:
Hi,
First of all, a web part would have viewstate. So you can very well
store
any intermediate data you need on the viewstate.
For doing a paging on a datagrid in a web part, you just have to set the
pagesize and allowpaging properties. Check the small code snippet below.
grid.AllowPaging = true;
grid.PageSize = 5;
grid.PageIndexChanged +=new
DataGridPageChangedEventHandler(grid_PageIndexChanged);
You can write the paging logic or associate a new page in the
pageindexchanged event as grid.CurrentPageIndex = e.NewPageIndex; and
bind
the grid to the datasource.
Hope this helps.
Regards,
Amar Galla
http://www.dotnetjunkies.com/weblog/amar
"jrmcdona" <jmc_1776@hotmail.com> wrote in message
news:26625E41-97A8-40DE-83B1-430F033879ED@microsoft.com...
Does anybody know where i can locate some sample code for doing
datagrid
sorting or paging within a web part. In my previous work, i have done
this
via a web application using view state. However, a web part does not
have
view state and I cannot seem to get this working correctly.
thanks!
|
|
|
| Back to top |
|
 |
Dave W.
Guest
|
Posted:
Thu Jan 13, 2005 7:11 pm Post subject:
Re: datagrid sorting/paging in a web part |
|
|
I got the paging working, it was because i was using UniqueID + "GridID" as
the setting for the ID of the datagrid... It wasn't working because the
datagrid changed the ID every post back.
Another problem that I seem to be having is that the CurrentPageIndex starts
at 0 and I can change the pages going up and coming back down until I try to
click on the 1st page. Once I leave the 0 page index, it never goes back to
it. the lowest the currentpageindex goes is 1. Is there a way i can tell the
datagrid to move to 0 or just start off at 1.
Thanks,
Dave |
|
| Back to top |
|
 |
|
|
|
|