2
Staff every time I try to remove a data on gridview I come across this error "The data source 'Sqldatasource2' does not support deletion unless Deletecommand is specified."
this is my method of excluding from gridview:
protected void TabelaAlimentos_DeleteRow(object sender, GridViewCommandEventArgs e)
{
if(e.CommandName == "Delete")
{
GerenciarAlimentacaoController controller = new GerenciarAlimentacaoController();
int index = Int32.Parse((string)e.CommandArgument);
int id = Int32.Parse(TabelaAlimentos.Rows[index].Cells[0].Text);
Alimento alimento = (Alimento)controller.pesquisar(id, "Alimentos");
controller.deletar(alimento);
TabelaAlimentos.DeleteRow(index);
TabelaAlimentos.DataBind();
FileInfo file = new FileInfo(Server.MapPath("~/img/Alimentos/") + alimento.imagemAlimento);
file.Delete();
Response.Write("<script language='javascript'> alert('Alimento Removido com Sucesso!'); window.location=('gerenciaralimentacao.aspx'); </script>");
}
}
Code is normally executed without error, but when exiting the method the error is generated.
Have you tried calling the Rebind(); method from your grid ?
– Marco Souza
How I use this method ?
– Erikson Aguiar
after the file. Delete(); seugridview.Rebind();
– Marco Souza
I don’t have access to that method
– Erikson Aguiar
I was able to resolve, what was missing was to activate the delete in sqldatasource,. Thanks for the help.
– Erikson Aguiar
This method is by Griview itself, you should have access yes, but good wants worked.
– Marco Souza
You tried to implement Row_deleting and/or Row_deleted remember methods?
– Guilherme Guini
I haven’t tried, but I’ll try, Thanks for the tip
– Erikson Aguiar