このリンクを使用しますが一意キーまたは主キーを必要としますカラム。列 "Serial_key"を使用してレコードを削除する場合。次に、次のコードをDeleteに設定します。
<ItemTemplate>
<asp:Label ID="lblSerial_key" runat="server" Text='<%# Eval("Serial_key") %>'></asp:Label>
<asp:Button ID="deleteButton" runat="server" CommandName="Delete" Text="Delete" /></ItemTemplate>
今、あなたは
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
string Serial_key = string.Empty;
Label lblId = (Label)GridView1.Rows[e.RowIndex].Cells[0].FindControl("lblSerial_key");
Serial_key = lblId.Text.ToString();
string selectSQL = "delete from tablename where id='" + Serial_key + "'";
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
// Create the command object
con.Open();
SqlCommand cmd = new SqlCommand(selectSQL , con);
cmd.ExecuteNonQuery();
con.Close();
}
行を削除するlblSerial_keyを使用することができ、あなたのコードのすべてのですか? –