Advertisement
Milotronik

Linq 9

Jun 7th, 2012
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
ASP 1.23 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.UI;
  6. using System.Web.UI.WebControls;
  7. using System.Data.Linq.SqlClient;
  8.  
  9.     /*
  10.      * Seleccione todas las filas de la tabla Customers agrupados por City.
  11.      * Muestre los resultados en un GridView.
  12.      *
  13.      */
  14.  
  15. public partial class _9 : System.Web.UI.Page
  16. {
  17.     protected void Page_Load(object sender, EventArgs e)
  18.     {
  19.         DataClassesDataContext db = new DataClassesDataContext();
  20.  
  21.         var query = from cust in db.Customers
  22.                     group cust by cust.City;
  23.  
  24.         List<Object> group= new List<Object>();
  25.  
  26.         /*
  27.          * Creo un listado porque el group hace grupos de customers por ciudades,
  28.          * entonces el GridView no puede mostrar grupos, sólo puede
  29.          * mostrar 1 grupo a la vez.
  30.          *
  31.          * De esta forma, recorro cada valor de cada grupo y lo
  32.          * agrego a una lista que después la muestro en el GridView.
  33.          */
  34.  
  35.         foreach (var customer in query) {
  36.             foreach (var cust in customer) {
  37.                 group.Add(cust);
  38.             }
  39.         }
  40.  
  41.         GridView1.DataSource = group;
  42.         GridView1.DataBind();
  43.     }
  44.  
  45.  
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement