Click here to Skip to main content
15,899,935 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi guyss,
I am working On Gridview Row Deleting event So.I getting this error

ArgumentOutOfRangeException was caught
Specified argument was out of the range of valid values. Parameter name: index

Code-

C#
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            try
            {

                objBusinessUI.RouteID = Int32.Parse(GridView1.DataKeys[e.RowIndex].Value.ToString());
                objBusinessUI.UpdatedBy = "Admin";
                objBusinessUI.UpdatedOn = DateTime.Now;
                string strMsg = objDataUI.DeleteRoute(objBusinessUI);
                if (strMsg == "SUCCESS")
                {
                    lblErrorMSG.Text = "Record deleted successfully";
                }
                else
                {
                    lblErrorMSG.Text = "There is problem in deleting record!Please try later";
                }

            }
            catch (Exception ex)
            {
              log.Error(System.Reflection.MethodBase.GetCurrentMethod().ToString() + ex.StackTrace);
            }


At the time of debugging focus comes on objBusinessUI.RouteID,first line..immediately its goes to the exception block..i dont uderstand whats is cause..and one more thing i am wanna note here..Its cascading ..Means RouteId child node and AreaID is passed as a FK..so its cause this problem .
Thakxxxxx in advance
Posted
Comments
anuradha.sardesai 17-Oct-13 2:23am    
Paste your html / aspx here, to see the grid properties
indrajeet jadhav 17-Oct-13 2:27am    
<%@ Page Title="" Language="C#" MasterPageFile="~/Area/Area.Master" AutoEventWireup="true" CodeBehind="AddRoute.aspx.cs" Inherits="WebApp.Area.WebForm3" %>
<%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="cc1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
<style type="text/css">
.style1
{
width: 100%;
}
.style2
{
width: 95%;
}
.style3
{
}
.style4
{
width: 21%;
}
.style5
{
width: 56px;
}
.style6
{
}
.style7
{
width: 106px;
}
</style>

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<table class="style1">
<tr>
<td>
<table class="style2">
<tr>
<td class="style7">
 </td>
<td>
 </td>
</tr>
<tr>
<td class="style7">
<asp:Label ID="lblArea" runat="server" Text="Area">
</td>
<td>
<asp:DropDownList ID="cmbArea" runat="server" Height="27px" Width="134px"
DataTextField="AreaName" DataValueField="AreaID">

</td>
</tr>
<tr>
<td class="style7">
<asp:Label ID="lblRouteName" runat="server" Text="Route Name">
</td>
<td>
<asp:TextBox ID="txtRouteName" runat="server">
</td>
</tr>
<tr>
<td class="style7">
<asp:Label ID="lblRouteCode" runat="server" Text="Route Code">
</td>
<td>
<asp:TextBox ID="txtRouteCode" runat="server">
</td>
</tr>
<tr>
<td class="style7">
 </td>
<td>
 </td>
</tr>
<tr>
<td class="style7">
 </td>
<td>
<table class="style4">
<tr>
<td class="style5">
<asp:Button ID="btnSave" runat="server" onclick="btnSave_Click" Text="Save" />
</td>
<td>
<asp:Button ID="btnReset" runat="server" Text="Reset" />
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td class="style6" colspan="2">
<asp:Label ID="lblErrorMSG" runat="server" BackColor="#FFFF66"
BorderColor="Yellow" ForeColor="Red">
</td>
</tr>
<tr>
<td class="style7">
 </td>
Madhu Nair 17-Oct-13 2:33am    
Where is the Grid in the HTML above?
indrajeet jadhav 17-Oct-13 3:05am    
Thnxx Madhu ..The problem is ..i forget DataKeyNames assigning value

1 solution

I think the problem lies in the below code-
C#
GridView1.DataKeys[e.RowIndex].Value


Have you specified any value for DataKeyNames for the grid in the aspx file? If not, do so.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900