protected void gv_pedidos_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
int idPedido = Convert.ToInt32(gv_pedidos.DataKeys[e.RowIndex].Values["idPedido"].ToString());
SqlConnection con = new SqlConnection(@"Server=localhost\SQLEXPRESS;Database=Kirchesch;Trusted_Connection=True;");
SqlCommand com = new SqlCommand(@"DELETE FROM pedidosFeitos WHERE idPedido = @idPedido", con);
com.Parameters.AddWithValue("@idPedido", idPedido);
con.Open();
com.ExecuteNonQuery();
con.Close();
preencheGrid();
}
这是我的代码的后端,我得到的错误是变量idPedido
,即第三行。
答案 0 :(得分:0)
只需使用Convert.ToInt32(e.RowIndex);
从所选行索引
中选择数据键进行操作答案 1 :(得分:0)
您可以在idPedido
事件中获得RowDeleting
这样的内容:
int idPedido = int.Parse(gv_pedidos.Rows[e.RowIndex].FindControl("idPedido").toString());