Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
215
Changing the datasource
posted

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

  • 1005
    Offline posted

    I have the exact issue.  Any solution would be appreciated.

     

     

    Jeff