Error while deleting line in Gridview ASP.NET C#

Asked

Viewed 62 times

1

I have the following GridView:

inserir a descrição da imagem aqui

If I delete a line from Grid and try to save, it returns the following error

Input string was not in a correct format.

This error occurs as soon as it enters the method, in the first item of the list

objBonusValor.BonFxCodigo = Convert.ToInt32(faixaGrid.Split('$')[0]);

But when I include a line and save it from the right.

Follows codes.

Save event:

 protected void btnSalvar_Click(object sender, EventArgs e)
{
    try
    {
        List<BonusValor> listaBonus = MontarListaBonusValor();
        if (listaBonus.Count > 0) 
        {
            using (TransactionScope trans = new TransactionScope(TransactionScopeOption.Required, PCIGlobal.SetarOpcoesTransacao()))
            {
                BonusValor objBonusValor = new BonusValor();
                objBonusValor.DeletarBonusValor();
                foreach (var faixa in listaBonus)
                {
                    faixa.InserirFaixaValor();
                }
                trans.Complete();
                trans.Dispose();
            } 
            mensagens.ExibirMensagem("Mensagem", mensagens.strMsgIncluido, true, this.Page, this.GetType());
        }
    }
    catch (Exception ex)
    {

        metodos.AnalizarErro(ex.Message, Request.CurrentExecutionFilePath, this.Page, this.GetType());
        mensagens.ExibirMensagem("Erro", mensagens.strMsgErroGenerico, false, this.Page, this.GetType());
    }
}

Montarlistabonus method():

 protected List<BonusValor> MontarListaBonusValor()
{
    try
    {
        List<BonusValor> lista = new List<BonusValor>();
        for (int i = 0; i < hdfTable.Value.Split('|').Length; i++)
        {
            if (hdfTable.Value.Split('|')[i].Trim().Length > 0)
            {
                BonusValor objBonusValor = new BonusValor();
                string faixaGrid = hdfTable.Value.Split('|')[i].Trim();
                if (!string.IsNullOrEmpty(faixaGrid))
                {
                    objBonusValor.BonFxCodigo = Convert.ToInt32(faixaGrid.Split('$')[0]);
                    objBonusValor.BonFxVlrInicial = Convert.ToDecimal(faixaGrid.Split('$')[1]);
                    objBonusValor.BonFxVlrFinal = Convert.ToDecimal(faixaGrid.Split('$')[2]);
                    objBonusValor.BonFxVlrBonus = Convert.ToDecimal(faixaGrid.Split('$')[3]);
                    objBonusValor.BonFxIdInc = Session["login"].ToString();
                    objBonusValor.BonFxDtInc = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss");
                }
                lista.Add(objBonusValor);
            }

        }
        return lista;
    }
    catch (Exception ex)
    {

        throw ex;
    }
}
  • 1

    Have you seen what’s in your faixaGrid.Split('$')[0] ? try playing in a variable to debug .

  • 1

    He also has: https://answall.com/q/191384/18246

No answers

Browser other questions tagged

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