Step :2
main.cs
body
{
background-color:Gray;
}
#div1
{
background-color: #FFFFCC; color: #000080; position: absolute;
width:700px; height: 450px;
padding-left: 20px; border-color:Maroon; border-style:solid; border-width:
4px; font-size:16px;
}
table
{
width : 700px; vertical-align:top;
}
#td1
{
width : 200px;vertical-align:top; text-align:left;
}
#td2
{
width : 500px;vertical-align:top; text-align:left;
}
#GridView1
{
width : 200px; border-style: solid; border-width:2px; border-color:Navy;
}
Code Student.cs
using System;
using System.Data;
using System.Linq;
using System.Linq.Expressions;
using System.Collections.Generic;
/// <summary>
/// Summary description for Player
/// </summary>
public class Student
{
public string Name { get; set; }
public string Subject { get; set; }
public int CourseID { get; set; }
public List<int> Scores { get; set; }
public Student()
{
//
// TODO: Add constructor logic here
//
}
}
Code Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"
Inherits="_Default" Debug="true" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>mm.LINQIntro8</title>
<link href="main.css" rel="stylesheet" type="text/css" />
</head>
<body>
<form id="form1" runat="server">
<div id="div1">
<table style="width:100%;">
<tr><td colspan="2" >
Example of Using SelectMany with var and IENumerable</td>
</tr>
<tr>
<td id="td1" >
 <asp:GridView ID="GridView1" runat="server" >
</asp:GridView>
</td>
<td id="td2">
<asp:Label ID="L1" runat="server" Text=""></asp:Label></td>
</tr>
<tr>
<td colspan="2" >
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
Code Defaultaspx.cs
using System;
using System.Data;
using System.Linq;
using System.Linq.Expressions;
using System.Collections.Generic;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
List<Student> students = new List<Student>()
//Student[] students =
{ new Student {Name="David",CourseID= 101, Subject="Chemistry",Scores= new
List<int> {99, 92, 94, 79} },
new Student {Name="Daniel",CourseID= 101, Subject="Chemistry",Scores= new
List<int> {97, 94, 81, 86} },
new Student {Name="Peter",CourseID= 102, Subject="English",Scores= new
List<int> {98, 96, 81, 94} },
new Student {Name="John",CourseID= 102, Subject="English",Scores= new
List<int> {96, 99, 86, 60} },
new Student {Name="Kavin",CourseID= 102, Subject="Chemistry",Scores= new
List<int> {97, 92,89, 88} },
new Student {Name="Brandon",CourseID= 102, Subject="English",Scores= new
List<int> {97, 99, 91, 90} }
};
var query1 = from s in students where s.Scores[0]>80 select new { name =
s.Name, subject = s.Subject, score0 = s.Scores[0],score1 =
s.Scores[1],score2 =s.Scores[2] };
GridView1.DataSource = query1;
GridView1.DataBind();
foreach (var item in query1)
{
L1.Text += item.name + " ," + item.subject + " :" + item.score0 + " ," +
item.score1 + " ," + item.score2 + " Avg: "+((item.score0 + item.score1 +
item.score2)/3) + "<br/>";
}
}
}