Click here to Skip to main content
15,918,808 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm trying to delete row from gridview but when it runs and I press delete button, nothing happens:
C#
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
    if (e.CommandName.Equals("Delete"))
    {
       int index = Convert.ToInt32(e.CommandArgument);
       var id = ((Label)GridView1.Rows[index].Cells[0].FindControl("id")).Text.Trim();

       SqlConnection con = new SqlConnection(connstring);
       string qry = "Delete from ['ISB VAS Nodes$'] where ID = " + id + "";
       SqlCommand com = new SqlCommand(qry, con);

       if (com.ExecuteNonQuery() == 1)
       {
           Label2.Text = "Deleted";
           binddata();
        }
        else
        {
           Label2.Text = "Not Deleted";
        }
     }
}
Posted
Updated 23-Apr-13 0:57am
v3

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