add blank line to a list

Asked

Viewed 55 times

1

I have a list already with data and I want every 3 lines to add a blank line in this list. To then move to a grid. How can I do that? For now the code is like this:

        anoanterior = Convert.ToString(fano);
        mesanterior = Convert.ToString(fmes);
        TAB_F_TABELAS_DAL d = new TAB_F_TABELAS_DAL();
        var dados = d.RetornaCronograma(anotual+mesatual, 
        anoanterior+mesanterior);   
        CT01_Array.DataSource = dados;
        CT01_Array.DataBind();

code in class:

        List<eCT01> lst = new List<eCT01>();
        OpenConnection();
        using (Cmd = new OracleCommand(sql, Con))
        {
            Cmd.CommandType = System.Data.CommandType.Text;
            OracleDataReader dr = Cmd.ExecuteReader();

            while (dr.Read())
            {
                eCT01 l = new eCT01();


                l.CICLO = dr["CICLO"].ToString();
                if(dr["MEDICAOMES"].ToString().Length == 5) { 
                 l.MEDICAO = "0" + dr["MEDICAOMES"].ToString();
                }
                else
                {
                    l.MEDICAO = dr["MEDICAOMES"].ToString();
                }
                l.DT_BLOQ_CICLO = dr["DT_BLOQ_CICLO"].ToString();
                l.DT_LEITURA_HD = dr["DT_LEITURA_HD"].ToString();
                l.DT_ENT_LEITUR = dr["DT_ENT_LEITUR"].ToString();
                l.DT_EMIS_CT_BLOQ = dr["DT_EMIS_CT_BLOQ"].ToString();
                l.DT_ENT_CT_BLOQ = dr["DT_ENT_CT_BLOQ"].ToString();
                l.DT_VENC_OPC1 = dr["DT_VENC_OPC1"].ToString();
                l.DT_VENC_OPC2 = dr["DT_VENC_OPC2"].ToString();
                l.DT_VENC_OPC3 = dr["DT_VENC_OPC3"].ToString();
                l.DT_VENC_OPC4 = dr["DT_VENC_OPC4"].ToString();
                l.DT_VENC_OPC5 = dr["DT_VENC_OPC5"].ToString();
                l.DT_VENC_OPC6 = dr["DT_VENC_OPC6"].ToString();
                l.VLR_M3 = dr["VLR_M3"].ToString();
                l.VLR_M3_SEM_ESG = dr["VLR_M3_SEM_ESG"].ToString();
                l.VLR_M3_COM_ESG = dr["VLR_M3_COM_ESG"].ToString();
                l.VLR_TARIFA_SOCIAL = dr["VLR_TARIFA_SOCIAL"].ToString();
                l.PERC_REC_HIDRICOS = dr["PERC_REC_HIDRICOS"].ToString();
                l.PERC_TX_REGULACAO = dr["DT_ENT_LEITUR"].ToString();

                lst.Add(l);
            }
            dr.Close();
        }
        CloseConnection();
        #endregion

        return lst;

1 answer

1


Rafael Veloso, you can make a "mod" that in C# is the "%" symbol in this way:

eCT01 lx = new eCT01();
if(num % 3 == 0) lst.Add(lx);

... but you will need an "num" counter to know which line you are on.

  • Note that lst is typed this way it is not possible to add a value that is not of the same type as the List.

  • @davidterra , and if you pass a blank value? Thus: "eCT01 lx = new eCT01();"

  • The problem with doing this is that I end up skipping a data line. because of this "while" type it reads and instead of adding a data line it adds a blank line and already goes to the next line.

  • @rafael-Veloso , but there’s no way you can do after "lst. Add(l);"?

  • Guys, I got it done!! Thank you very much! Sorry for the delay in answering

Browser other questions tagged

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