Error while removing data in Gridview Asp.net c#

Asked

Viewed 178 times

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 ?

  • How I use this method ?

  • after the file. Delete(); seugridview.Rebind();

  • I don’t have access to that method

  • 1

    I was able to resolve, what was missing was to activate the delete in sqldatasource,. Thanks for the help.

  • This method is by Griview itself, you should have access yes, but good wants worked.

  • You tried to implement Row_deleting and/or Row_deleted remember methods?

  • I haven’t tried, but I’ll try, Thanks for the tip

Show 3 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.