This is a migrated thread and some comments may be shown as answers.

Remove Column error - Index was out of range.

4 Answers 163 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Brandon
Top achievements
Rank 1
Brandon asked on 07 Aug 2008, 08:08 PM
Telerik.Web.UI : runtime = v2.0.50727, ver = 2008.2.723.20

Error when removing column from grid.

Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
 

Process I am going through:

1. user selects add column on the page
2. Post back, add column to datasource
3. rebind grid
    (grab data from datasource, clear columns from grid, add all current columns)
4. user selects delete column
5. confirm delete
6. postback, delete column from datasource
7. rebind grid
    (grab data from datasource, clear columns from grid, add all current columns)

This works if all of this is done continuously. However, if I navigate off of this page at before step 4 and return to the page and continue, then I receive the error above.

Note: on NeedDataSource event I am setting datagrid.DataSource to the System.Data.DataTable

i dont know if it has to do with the viewstate? i tried to provide as much info as i can, let me know if anything else is required.

------------------------------

[External Code]
  System.Web.RegularExpressions.dll!System.Web.Util.CalliHelper.EventArgFunctionCaller(System.IntPtr fp, object o, object t, System.EventArgs e) + 0x10 bytes 
  System.Web.dll!System.Web.Util.CalliEventHandlerDelegateProxy.Callback(object sender, System.EventArgs e) + 0x22 bytes 
  System.Web.dll!System.Web.UI.Control.OnLoad(System.EventArgs e) + 0x64 bytes 
  System.Web.dll!System.Web.UI.Control.LoadRecursive() + 0x30 bytes 
  System.Web.dll!System.Web.UI.Page.ProcessRequestMain(bool includeStagesBeforeAsyncPoint = true, bool includeStagesAfterAsyncPoint = true) + 0x59d bytes 
  System.Web.dll!System.Web.UI.Page.ProcessRequest(bool includeStagesBeforeAsyncPoint, bool includeStagesAfterAsyncPoint = true) + 0x67 bytes 
  System.Web.dll!System.Web.UI.Page.ProcessRequest() + 0x57 bytes 
  System.Web.dll!System.Web.UI.Page.ProcessRequestWithNoAssert(System.Web.HttpContext context) + 0x13 bytes 
  System.Web.dll!System.Web.UI.Page.ProcessRequest(System.Web.HttpContext context) + 0x32 bytes 
  App_Web_3crb2jk7.dll!ASP.error_error_aspx.ProcessRequest(System.Web.HttpContext context = {System.Web.HttpContext}) + 0x2f bytes C#
  System.Web.dll!System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() + 0x167 bytes 
  System.Web.dll!System.Web.HttpApplication.ExecuteStep(System.Web.HttpApplication.IExecutionStep step = {System.Web.HttpApplication.CallHandlerExecutionStep}, ref bool completedSynchronously = true) + 0x41 bytes 
  System.Web.dll!System.Web.HttpApplication.ApplicationStepManager.ResumeSteps(System.Exception error) + 0x1b3 bytes 
  System.Web.dll!System.Web.HttpApplication.System.Web.IHttpAsyncHandler.BeginProcessRequest(System.Web.HttpContext context, System.AsyncCallback cb, object extraData) + 0x8e bytes 
  System.Web.dll!System.Web.HttpRuntime.ProcessRequestInternal(System.Web.HttpWorkerRequest wr = {Microsoft.VisualStudio.WebHost.Request}) + 0x1b5 bytes 
  System.Web.dll!System.Web.HttpRuntime.ProcessRequestNoDemand(System.Web.HttpWorkerRequest wr) + 0x62 bytes 
  System.Web.dll!System.Web.HttpRuntime.ProcessRequest(System.Web.HttpWorkerRequest wr) + 0x38 bytes 
  WebDev.WebHost.dll!Microsoft.VisualStudio.WebHost.Request.Process() + 0x113 bytes 
  WebDev.WebHost.dll!Microsoft.VisualStudio.WebHost.Host.ProcessRequest(Microsoft.VisualStudio.WebHost.Connection conn = {System.Runtime.Remoting.Proxies.__TransparentProxy}) + 0x5c bytes 
  [Appdomain Transition] 
  WebDev.WebHost.dll!Microsoft.VisualStudio.WebHost.Server.OnSocketAccept(object acceptedSocket) + 0x86 bytes 
  mscorlib.dll!System.Threading._ThreadPoolWaitCallback.WaitCallback_Context(object state) + 0x1a bytes 
  mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) + 0x81 bytes 
  mscorlib.dll!System.Threading._ThreadPoolWaitCallback.PerformWaitCallbackInternal(System.Threading._ThreadPoolWaitCallback tpWaitCallBack) + 0x50 bytes 
 mscorlib.dll!System.Threading._ThreadPoolWaitCallback.PerformWaitCallback(object state) + 0x60 bytes 


4 Answers, 1 is accepted

Sort by
0
Accepted
Vlad
Telerik team
answered on 11 Aug 2008, 08:07 AM
Hello Brandon,

Can you verify what will be result if you set MasterTableView.EnableColumnsViewState to false?

Regards,
Vlad
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Brandon
Top achievements
Rank 1
answered on 11 Aug 2008, 06:37 PM
Thanks! Setting this property to false fixed my issue.

My problem is solved but I was wondering, if i was to leave the MasterTableView.EnableColumnsViewState set to true, what is the appropriate way to tell the grid that the column is marked to be deleted.

Its not a big deal if you dont answer my new question, I am just asking because I'm curious.

Anyways, thanks again!

-Brandon
0
Vlad
Telerik team
answered on 12 Aug 2008, 05:54 AM
Hello Brandon,

By default the grid columns are stored in ViewState and grid will try to recreate them on subsequent post backs. Add/remove columns on the fly with turned on ViewState is not supported - you can use Visible property for example to show/hide columns instead. When you turn off the columns ViewState you can safely add and/or remove columns on the fly without messing the grid state.

Sincerely yours,
Vlad
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Srinivas
Top achievements
Rank 1
answered on 18 Jan 2011, 10:02 PM
Thanks for providing a nice solution. It has resolved my issue.
Tags
Grid
Asked by
Brandon
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Brandon
Top achievements
Rank 1
Srinivas
Top achievements
Rank 1
Share this question
or