need help . i am deleting particular row in my grid
there is a delete button in my edititem template
<asp:TemplateField HeaderText="Edit">
<ItemTemplate>
<asp:Button ID="btnedit" runat="server" Text="Edit" />
<asp:Button ID="btnDelete" runat="server" Text="Detete" />
</ItemTemplate>
<EditItemTemplate>
<asp:Button ID="btnupdate" CommandName="update" runat="server" Text="Edit" />
<asp:Button ID="btncancel" CommandName="cancel" runat="server" Text="Detete" />
</EditItemTemplate>
;
and my c# codes are
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=master;Integrated Security=True");
SqlCommand cmd=new SqlCommand();
con.Open();
int idd = Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Values["id"].ToString());
Button delete = (Button)GridView1.Rows[e.RowIndex].FindControl("btncancel");
if(delete.CommandName=="caancel")
// int idd = Int32.Parse(GridView1.DataKeys[e.RowIndex].Values["id"].ToString());
cmd = new SqlCommand("delete from food where id="+idd, con);
cmd.ExecuteNonQuery();
con.Close();
GridView1.DataBind();
}
and i am getting this error
Exception Details: System.Web.HttpException: Multiple controls with the same ID 'lname' were found. FindControl requires that controls have unique IDs.
sir i want to know the reason why this error is coming and what i am missing in my codes. this is a learning experience so i request to you sir please help me i am a new student