Click here to Skip to main content
15,921,793 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
C#
protected void Deactivate_Click(object sender, EventArgs e)
    {

        LinkButton lnk = sender as LinkButton;
        
        GridViewRow gridrow = lnk.NamingContainer as GridViewRow;
        int userid = Convert.ToInt32(GridView1.DataKeys[gridrow.RowIndex].Value.ToString());
        string username = gridrow.Cells[0].Text;
        con.Open();
        
        OleDbCommand cmd1 = new OleDbCommand("Delete from SlideShowTable1 WHERE U_id=" + userid, con);
        result = cmd1.ExecuteNonQuery();

        con.Close();

        if (result > 0)
        {
            BindEmployeeDetails();
            BindEmployeeDetails1();

            ScriptManager.RegisterStartupScript(this, this.GetType(), "alertmessage", "javascript:alert('" + username + "  Deactivated successfully')", true);

        }

    }
Posted
Updated 17-Apr-13 8:09am
v2
Comments
Thomas Daniels 17-Apr-13 14:09pm    
In which line do you get the error?
Amirsalgar1 17-Apr-13 14:20pm    
int userid = Convert.ToInt32(GridView1.DataKeys[gridrow.RowIndex].Value.ToString());
Amirsalgar1 17-Apr-13 14:20pm    
this one
fjdiewornncalwe 17-Apr-13 14:09pm    
What line to do get the error on. That will go a long way to solving your issue.
Amirsalgar1 17-Apr-13 14:19pm    
int userid = Convert.ToInt32(GridView1.DataKeys[gridrow.RowIndex].Value.ToString());

1 solution

Without knowing which line it is complaining about we can't be precise. But it's one of two lines:
C#
int userid = Convert.ToInt32(GridView1.DataKeys[gridrow.RowIndex].Value.ToString());
string username = gridrow.Cells[0].Text;
Either gridRow is not a row in the GridView1 control, or there are no cells in the row. Check both, and work out which. You may want to look at when this happens, and if anything sensible is assigned to gridRow at that point.
 
Share this answer
 
Comments
Amirsalgar1 17-Apr-13 14:21pm    
okay ..
i ll check it ..thank you sir
OriginalGriff 17-Apr-13 14:26pm    
You're welcome!

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