Is there a way to clear the viewstate for the grid in order to change the datasource from the code behind?
I have a requirement that the users are able to change the datasource being viewed in the grid at any time or basically recreate the grid with a new datasource. Currently I have EnableViewState = True in order to handle the user doing filtering,grouping,sorting..... This works well for a single dataset but appears to crash when changing the data being viewed because the grid isn't recognizing that the columns have changed. If I i disable the view state, changing the dataset works but I loose other functionality generally stored in the viewstate.
Scenario:
The user loads the grid displaying a small datatable with 4 columns, after reviewing the data they change to a different dataset with 20 columns.
On switching the dataset I have cleared all bands,rows,columns and behaviors from the original grid and created new bands,columns,behaviors for the new grid. When debugging the grid and new bands show the correct number of columns but they just don't rendor properly if EnableViewState is True. The second dataset renders in the original 4 columns if the keys match.
If the new dataset has predefined behaviors such as column sorting the grid crashes sbecause it trys to apply a behavior to the grid that the viewstate says doesn't exist.
[NullReferenceException: Object reference not set to an instance of an object.] Infragistics.Web.UI.GridControls.Sorting.AddHeaderImgToCaption(GridField column, SortDirection direction) +442 Infragistics.Web.UI.GridControls.Sorting.BehaviorEvents_PreRender(Object sender) +160 Infragistics.Web.UI.GridControls.RenderingContentHandler.Invoke(Object sender) +0 Infragistics.Web.UI.GridControls.GridRenderer.RenderContents(HtmlTextWriter writer) +169 Infragistics.Web.UI.GridControls.HierarchicalGridRenderer.RenderContents(HtmlTextWriter writer) +641 Infragistics.Web.UI.Framework.RunBot.HandleRenderContents(HtmlTextWriter writer, RendererBase renderer) +248 Infragistics.Web.UI.Framework.Data.HierarchicalDataBoundControlMain.Render(HtmlTextWriter writer) +25 System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +245 System.Web.UI.HtmlControls.HtmlForm.RenderChildren(HtmlTextWriter writer) +314 System.Web.UI.HtmlControls.HtmlContainerControl.Render(HtmlTextWriter writer) +47 System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +245 System.Web.UI.Page.Render(HtmlTextWriter writer) +39 System
Thanks for any help or suggestions
Hello leas3c,
If you would like to clear the datasource, you should do as Dr Tone suggested.
Let me know if you need further assistance with this.
Regards,
Lyuba
Developer Support Engineer
Infragistics
www.infragistics.com/support
Hi,
I'm also facing the same issue. Even after clearing the datasource, viewstate of webdatagrid, its still giving me this error at render of control. This happens only when I do sorting then rebind of grid with different datasource. Please help. Its urgent.
at Infragistics.Web.UI.GridControls.Sorting.AddHeaderImgToCaption(GridField column, SortDirection direction) at Infragistics.Web.UI.GridControls.Sorting.BehaviorEvents_PreRender(Object sender) at Infragistics.Web.UI.GridControls.GridBehaviorEvents.RenderingContentHandler.Invoke(Object sender) at Infragistics.Web.UI.GridControls.GridRenderer.RenderContents(HtmlTextWriter writer) at Infragistics.Web.UI.Framework.RunBot.HandleRenderContents(HtmlTextWriter writer, RendererBase renderer) at Infragistics.Web.UI.Framework.Data.FlatDataBoundControl.Render(HtmlTextWriter writer) ....................
TIA