ViewState problem

A

Al Cadalzo

I am having a performance problem with a datagrid control that has a large
viewstate due to several columns containing very long href's in the
hyperlinks. I need the enableviewstate = true to enable paging
(AllowPaging=true,PageSize=50). If I don't enableViewState on the DataGrid
then my PageIndex_Changed handler doesn't get executed. I retrieve fresh
data each time I postback, so I don't actually need the datagrid's items in
the viewState, all I need is the page number. Is there a way that I can
use ViewState just to enable the PageIndex_Changed handler to work, without
passing the dataGrid's dataitems in ViewState? Maybe someone has written
their own code to enabling paging so that the DataGrid's viewstate can be
turned off?

Thanks,
Al
 
M

Marshal Antony

Hi,
You can disable viewstate for each item in your datagrid.If you disable
viewstate in DataGridItems only,paging and
post back will work.You can do so by disabling view state of datagrid items
in the PreRender event handler.
private void Page_PreRender(object sender,EventArgs e){
foreach(DataGridItem dg in DataGrid1.Items){

dg.EnableViewState=false;

}

}
Hope this helps.
Regards,
Marshal Antony
..NET Developer
http://www.dotnetmarshal.com
 
A

Al Cadalzo

Marshal,

I had no idea you could turn it off on individual datagrid items. At first
the paging didn't work, so I added an IF ItemType == ListItemType.Item
dg.EnableViewState=false;

and then the paging worked again. It improved the performance greatly.

Many thanks,
Al
 

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,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top