using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial
class _Default : System.Web.UI.Page

{
protected
void Page_Load(
object sender, EventArgs e)

{
if (!IsPostBack)

{

DataClassesDataContext dc =
new DataClassesDataContext(System.Configuration.ConfigurationManager.ConnectionStrings[
"MoviesConnectionString"].ToString());
this.GridView1.DataSource = dc.Movies;
this.GridView1.DataBind();
this.BindDropDowList();

}

}
protected
void Button1_Click(
object sender, EventArgs e)

{

IQueryable<Movy> Iquery=
null;
int id =
int.Parse(DropDownList1.SelectedValue);
switch (id)

{
case -1:

Iquery = from movie
in
new DataClassesDataContext().Movies select movie;
break;
default:

Iquery = from movie
in
new DataClassesDataContext().Movies

where movie.ID == id

select movie;
break;

}
this.GridView1.DataSource = Iquery;
this.GridView1.DataBind();

}
protected
void BindDropDowList()

{

DataClassesDataContext dc =
new DataClassesDataContext(System.Configuration.ConfigurationManager.ConnectionStrings[
"MoviesConnectionString"].ToString());
this.DropDownList1.DataSource = dc.Movies.ToList();
this.DropDownList1.DataTextField =
"Movie_Name";
this.DropDownList1.DataValueField =
"Id";
this.DropDownList1.DataBind();
this.DropDownList1.Items.Insert(0,
new ListItem(
"全部",
"-1"));

}
protected
void GridView1_RowDataBound(
object sender, GridViewRowEventArgs e)

{
if (e.Row.RowType == DataControlRowType.DataRow)

{

e.Row.Attributes.Add(
"onMouseOver",
"SetNewColor(this);");

e.Row.Attributes.Add(
"onMouseOut",
"SetOldColor(this);");

}

}

}