Click here to Skip to main content
15,919,931 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
C#
protected void gdvErrorlog_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        try
        {
            ErrorLogDetails delerror = new ErrorLogDetails();
            GridViewRow Row = (GridViewRow)gdvErrorlog.Rows[e.RowIndex];
            ErrorId = Convert.ToInt32(gdvErrorlog.DataKeys[e.RowIndex].Values["ErrorId"]);
            EID = Convert.ToInt32(ErrorId.ToString());
            delerror.UserName = username;
            delerror.ErrorID = EID;
            delerror.delerror();
            gdvErrorlog.EditIndex = -1;
            LoadErrorDetails();
            
        }
        catch(Exception ex)
        {
            
        }
    }
Posted
Updated 31-May-12 21:23pm
v2
Comments
Herman<T>.Instance 1-Jun-12 3:24am    
on which line the exception is given?

You need to look at it in a bit more detail - it would appear that e.RowIndex is either negative (indicating no such row) or referencing an already deleted row.
Put a break point on the first line of the event handler, and see when it get fired. Is the value negative? Does it get fired more than one for a single delete operation?
 
Share this answer
 
plesase check on which line is error coming. and check that what is the value of e.RowIndex. i think it is -1.
 
Share this answer
 
Comments
LALIT018 2-Jun-12 17:07pm    
ErrorId = Convert.ToInt32(gdvErrorlog.DataKeys[e.RowIndex].Values["ErrorId"]);
Sir in this line I am getting the error, Can you please suggest me how to code it properly.

Thanking You
first you need to check whether that data is in table or not...sometimes for empty table, it displays like the above error.
 
Share this answer
 
Make your the user has selected a row.
If this error rises that probably means the code is triggered even though there is
no row selected at the time. So the index is -1.
 
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