How to use the list when you do not know the object that will be returned?

Asked

Viewed 85 times

1

I have an Oracle database and need to popular a gridView. I’m doing with var, because I do not know the type that will be returned. It has to make a list in var, example list<var>, and then play in the grid?

gridview1.datasource = lista var
grindview1.dataBird():

foreach (var nota in info)
{
    var prod = bd.PRODUTOes.Where(p => p.NOTA_FISCAL.Any(n => n.ID == nota.ID));
}
  • 1

    Could you be more clear on your question? You have a grid on the screen that can be a list of multiple objects and needs it to be dynamic, that’s it?

  • How do you not know the type to be returned? It will always be a IEnumerable<T>, being T the type of PRODUTOes.

1 answer

1


I managed to solve:

DataTable dt = new DataTable();

dt.Columns.Add("nome");
dt.Columns.Add("VALOR_UNIT");

foreach(var nota in info)
{
   var prod = bd.PRODUTOes.Where(p => p.NOTA_FISCAL.Any(n => n.ID == nota.ID)).ToList();


   foreach(PRODUTO detalheProduto in prod)
   {
      dt.Rows.Add(detalheProduto.NOME, detalheProduto.VALOR_UNIT.ToString());
   }

}

GridView1.DataSource = dt;
GridView1.DataBind(); 

Browser other questions tagged

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