Ddelete in Gridview without using AutoGenerateDeleteButton
how to delete in Gridview row without using AutoGenerateDeleteButton?
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
Sreekanth ReddyRank #726 · 3.2K reputationPosted Jan 31, 2017, 5:44 PM EST
namespace WebApplication1
{
public partial class WebForm2 : System.Web.UI.Page
{
SqlConnection con = new SqlConnection("server=.;database=abc;trusted_connection=true");
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
bind();
}
}
public void bind()
{
SqlCommand cmd = new SqlCommand("select * from employee", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds, "con");
GridView1.DataSource = ds;
GridView1.DataBind();
}
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "comdel")
{
int l = Convert.ToInt32(e.CommandArgument);
con.Open();
SqlCommand cmd = new SqlCommand("delete from employee where eno=@a", con);
cmd.Parameters.AddWithValue("@a", l);
int i = cmd.ExecuteNonQuery();
if (i == 1)
{
Response.Write("Record deleted");
bind();
}
else
{
Response.Write("Recodrd not deleted...");
}
Page_Load(sender, e);
}
}
}
}