Note that there are some explanatory texts on larger screens.

plurals
  1. POGenerating Columns in GridView ( C#, LINQ )
    primarykey
    data
    text
    <p>The situation is, that i need to create table in grid view looking like this:</p> <p>----------| ID---|---Name--|--1/2002--|--2/2002--|--1/2003--|........| 2/2009 |<br> Cust1--|<br> Cust2--|<br> :<br> :<br> I have two tables in db - Customers and orders, throught LINQ to SQL DataContext<br> ID and Name of the customers i´m getting from a simple query</p> <pre><code>var custInfo = from cust in db.Customers select new { ID = cust.Id, FullName = cust.FirstName + " " + cust.LastName } dataGridOrdersPreview.DataSource = custInfo; </code></pre> <p>And i need some clue, how to generate that columns in format t/year where t indicates the first or second half of the year, and assign to that generated columns each Customer´s orders in that session of the year ( displaying only costs )</p> <p>[edit]</p> <p>As far as now, i´m attempting to something like this:</p> <pre><code>var orders = from ord in db.Orders group ord by ord.Id_cust into grouped let costs = grouped .Where( s =&gt; s.YearSession == session &amp;&amp; s.Year == year) .Select(a =&gt; new { Costs = a.Cost ) } ) select new { ID = grouped.Key, Name = custInfo .Where( a =&gt; a.ID == grouped.Key) .Select( j =&gt; j.Name).Single(), Cost = ExtensionLibrary.Sum(costs, "\n") }; </code></pre> <p>( in Cost getting only the summed costs in that year session for each customer )</p> <p>and then i think about iterating throuhgh the years and sessions and getting somehow the query results to corresponding columns</p> <pre><code>while (year &lt;= DateTime.Today.Year) { year++; while (session &lt; 2) { session++; dataGridOrdersPreview.Columns.Add(session +"/"+ year); col.Add((session +"/"+ year), orders.Select( a =&gt; a.Cost ).ToList() ); /* col is Dictionary&lt;string, List&lt;string&gt; &gt; */ } session = 0; } </code></pre> <p>Here i have generated columns that i want and i have orders in Dictionary where Key is column name and Value are orders in that column, but i need some help binding it to that columns</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload