First of All You have to bind your link button command Argument property
that's the value which will be pass to your store procedure so your record will be deleted
protected void lnkDelete_Click(object sender, EventArgs e)
{
LinkButton lnk = (LinkButton)sender;
SqlCommand cmd = new SqlCommand();
if (SqlCon != null && SqlCon.State != ConnectionState.Open)
{
SqlCon.Open();
}
cmd.Connection = SqlCon;
cmd.CommandText = "YOUR STORE PROCEDURE NAME";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("YOUR PARAMETER NAME",lnk.CommandArgument.ToString());
cmd.ExecuteNonQuery();
}
you can do this using this method also
for this you have to set command name and command argument property of link button
protected void GridView1_RowCommand(object sender,
GridViewCommandEventArgs e)
{
if (e.CommandName == "Delete";)
{
int categoryID = Convert.ToInt32(e.CommandArgument);
SqlCommand cmd = new SqlCommand();
if (SqlCon != null && SqlCon.State != ConnectionState.Open)
{
SqlCon.Open();
}
cmd.Connection = SqlCon;
cmd.CommandText = "YOUR STORE PROCEDURE NAME";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("YOUR PARAMETER NAME",categoryID);
cmd.ExecuteNonQuery();
}
}