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