Itsme

Itsme

  • NA
  • 107
  • 4.9k

while deleting throwing error.

Oct 1 2019 4:40 AM
I want to delete selected record but it is giving me error--System.Web.HttpException: 'DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'Id'.'
<asp:TemplateField ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Center" >
                                    <ItemTemplate>
                                        <asp:ImageButton ID="ImageButton1" runat="server" Text="Delete"
                                        ImageUrl="~/Images/delete.png" Width="50px" Height="50px" CommandArgument='<%#     Eval("Id") %>'
                                        CommandName="Deleterow" />
                                    </ItemTemplate>
                                </asp:TemplateField>
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "Deleterow")
            {
                string id = e.CommandArgument.ToString();
                string constr = ConfigurationManager.ConnectionStrings["Q_SS_regnConnectionString1"].ConnectionString;
                SqlConnection con = new SqlConnection(constr);
                con.Open();
                SqlCommand sq = new SqlCommand("DELETE FROM Booking where Id='" + id + "'", con);
                sq.ExecuteNonQuery();
                con.Close();
            }
        }

Answers (3)