|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Datagrid viewstateIs there a way to selectively turn off viewstate for a datagrid?
I've implemented server side paging for the grid with an object datasource, and there's no reason to track the actual data in the grid in viewstate, but I still need to track the page and sort order. If you re-databind upon each postback the sort and paging would work. You
can also manage the sort and the paging by custom coding. For example, to sort the datagrid all you need to know is what key the user wanted to sort by. You can then have the HeaderText as an anchor tag that triggers a click event of a Button with its commandArgument value set as the desired key for sorting. Inside the datagrid you would have in the column a definition for headerTemplate: <HeaderTemplate> <a href="javascript:SortBasedOn('Field1')">Field1</a> </HeaderTemplate> At the buttom of the webform you would add: <asp:Button CssClass="Hidden" EnableViewState="True" Runat="server" CommandArgument="Field1" OnCommand="datagrid1_Sort" CommandName="Sort" ID="btnField1"></asp:Button> Inside your Javascript section you would add: function SortBasedOn(KeyWord) { var btn= findControl("btn"+KeyWord); if (btn!=null) { btn.click(); } } And in the codebehind you would have a datagrid1_Sort function that responds to the button command event to recreate a dataview sorted based on the new sort key and databind it to the datagrid. Show quoteHide quote "Larry Charlton" wrote: > Is there a way to selectively turn off viewstate for a datagrid? > > I've implemented server side paging for the grid with an object datasource, > and there's no reason to track the actual data in the grid in viewstate, but > I still need to track the page and sort order.
C#/ASP.NET 2.0 - Convert HTML Table to DataGrid/Source
How to set property "ReadOnly" on all TextBoxes on a WebForm Composite Server Control and DefaultValue Attribute The case of the crazy reseting dropdowns :-( Please help! Looking for a book on writing ASP.NET Controls with VB.NET Type.GetType() Row count for query through SqlDataSource and GridView TreeView web control not displaying using ASPNET objects in custom webcontrol Indent Items in ASP:ListBox? |
|||||||||||||||||||||||