J
Jonathan Wood
I'm having my site email errors to me until I get things as stable as
possible. Occasionally, I get an error that I just cannot see how it could
ever happen. I enabled debugging on the live site so that I could get
line-number information. But I'm still at a loss.
I've posted an error below, and the code below that. Somehow,
grdWorkout.DataKeys[grdWorkout.SelectedIndex] is causing an
ArgumentOutOfRangeException, even though I had tested for SelectedIndex
== -1.
Does anyone have any clues as to how this could happen?
Thanks.
System.Web.HttpUnhandledException: Exception of type
'System.Web.HttpUnhandledException' was thrown. --->
System.ArgumentOutOfRangeException: Index was out of range. Must be
non-negative and less than the size of the collection.
Parameter name: index
at System.Collections.ArrayList.get_Item(Int32 index)
at System.Web.UI.WebControls.DataKeyArray.get_Item(Int32 index)
at ASP.Workouts.btnSubstitute_Click(Object sender, ImageClickEventArgs e)
in d:\Inetpub\medicorpmap\Controls\Workouts.ascx:line 155
at System.Web.UI.WebControls.ImageButton.OnClick(ImageClickEventArgs e)
at System.Web.UI.WebControls.ImageButton.RaisePostBackEvent(String
eventArgument)
at
System.Web.UI.WebControls.ImageButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String
eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
sourceControl, String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
at System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
--- End of inner exception stack trace ---
at System.Web.UI.Page.HandleError(Exception e)
at System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
at System.Web.UI.Page.ProcessRequest(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
at System.Web.UI.Page.ProcessRequest()
at System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context)
at System.Web.UI.Page.ProcessRequest(HttpContext context)
at ASP.trainer_workouts_aspx.ProcessRequest(HttpContext context) in
c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET
Files\root\f2d4905b\94fa3b3c\App_Web_amhr_qtk.2.cs:line 0
at
System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean&
completedSynchronously)
if (ddlWorkouts.Items.Count == 0)
{
ErrorMessage1.SetError("You must first create one or more workouts before
you can exchange workout items.");
}
else if (grdWorkout.SelectedIndex == -1)
{
ErrorMessage1.SetError("You must first select an activity in the workout
before you can exchange it.");
}
else
{
EncryptedQueryString queries = new EncryptedQueryString();
queries["UserID"] = UserID.ToString();
object obj = TrainerID;
if (obj != null)
queries["TrainerID"] = obj.ToString();
queries["WorkoutID"] = ddlWorkouts.SelectedValue;
queries["WorkoutDetailID"] =
grdWorkout.DataKeys[grdWorkout.SelectedIndex].Value.ToString(); // <=====
LINE 155
Response.Redirect(String.Format("{0}?data={1}", SubstituteItemUrl,
queries), true);
}
possible. Occasionally, I get an error that I just cannot see how it could
ever happen. I enabled debugging on the live site so that I could get
line-number information. But I'm still at a loss.
I've posted an error below, and the code below that. Somehow,
grdWorkout.DataKeys[grdWorkout.SelectedIndex] is causing an
ArgumentOutOfRangeException, even though I had tested for SelectedIndex
== -1.
Does anyone have any clues as to how this could happen?
Thanks.
System.Web.HttpUnhandledException: Exception of type
'System.Web.HttpUnhandledException' was thrown. --->
System.ArgumentOutOfRangeException: Index was out of range. Must be
non-negative and less than the size of the collection.
Parameter name: index
at System.Collections.ArrayList.get_Item(Int32 index)
at System.Web.UI.WebControls.DataKeyArray.get_Item(Int32 index)
at ASP.Workouts.btnSubstitute_Click(Object sender, ImageClickEventArgs e)
in d:\Inetpub\medicorpmap\Controls\Workouts.ascx:line 155
at System.Web.UI.WebControls.ImageButton.OnClick(ImageClickEventArgs e)
at System.Web.UI.WebControls.ImageButton.RaisePostBackEvent(String
eventArgument)
at
System.Web.UI.WebControls.ImageButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String
eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
sourceControl, String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
at System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
--- End of inner exception stack trace ---
at System.Web.UI.Page.HandleError(Exception e)
at System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
at System.Web.UI.Page.ProcessRequest(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
at System.Web.UI.Page.ProcessRequest()
at System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context)
at System.Web.UI.Page.ProcessRequest(HttpContext context)
at ASP.trainer_workouts_aspx.ProcessRequest(HttpContext context) in
c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET
Files\root\f2d4905b\94fa3b3c\App_Web_amhr_qtk.2.cs:line 0
at
System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean&
completedSynchronously)
if (ddlWorkouts.Items.Count == 0)
{
ErrorMessage1.SetError("You must first create one or more workouts before
you can exchange workout items.");
}
else if (grdWorkout.SelectedIndex == -1)
{
ErrorMessage1.SetError("You must first select an activity in the workout
before you can exchange it.");
}
else
{
EncryptedQueryString queries = new EncryptedQueryString();
queries["UserID"] = UserID.ToString();
object obj = TrainerID;
if (obj != null)
queries["TrainerID"] = obj.ToString();
queries["WorkoutID"] = ddlWorkouts.SelectedValue;
queries["WorkoutDetailID"] =
grdWorkout.DataKeys[grdWorkout.SelectedIndex].Value.ToString(); // <=====
LINE 155
Response.Redirect(String.Format("{0}?data={1}", SubstituteItemUrl,
queries), true);
}