Linq query in DataTable

I have a DataTable that is populated from a stored procedure. I am making a query in a DataTable using groupby so that I can implement a ListView in a ListView. (Matt Berseth - Grouping with LinqDataSource and ListView ASP.NET 3.5 Controls )

My request in my code:

var query = from c in dtTaskOrder.AsEnumerable() 
        group c by c.Field<string>("CLIN") into g
        select new
        {
            Key = g.Key,
            Count = g.Count(),
            Items = g
        };

listv.DataSource = query.ToList();
listv.DataBind();

In my aspx file, I try Eval on elements and subsequent columns:

<asp:ListView ID="lv1" ... DataSource='<%# Eval("Items") %>'>

   <td><%# Eval("SLIN") %></td> // column name
   <td><%# Eval("ACRN") %></td> // column name
   <td><%# Eval("Status") %></td> // last column name

The HttpException was not handled by the user code - when it tries to Eval by the names of the named columns.

How can I formulate the above query so that “Items” is “Typed” and I can use column names.

Thank you for your help.

+3
source share
2 answers

, g :

var query = from c in dtTaskOrder.AsEnumerable()
            group c by c.Field("CLIN") into g
            select new
            {
                Key = g.Key,
                Count = g.Count(),
                Items = from i in g
                        select new { CLIN = i.Field("CLIN"),
                                     ACRN = i.Field("ACRN"),
                                     Status = i.Field("Status") }
            };
+3

, Eval ( "SLIN" ), , Eval ( "CLIN" )? . , .

0

Source: https://habr.com/ru/post/1713068/


All Articles