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
![](https://ucc.alicdn.com/notfound.png?x-oss-process=image/resize,w_1400/format,webp)
{
protected
void Page_Load(
object sender, EventArgs e)
![](https://ucc.alicdn.com/notfound.png?x-oss-process=image/resize,w_1400/format,webp)
{
if (!IsPostBack)
![](https://ucc.alicdn.com/notfound.png?x-oss-process=image/resize,w_1400/format,webp)
{
![](https://ucc.alicdn.com/notfound.png?x-oss-process=image/resize,w_1400/format,webp)
DataClassesDataContext dc =
new DataClassesDataContext(System.Configuration.ConfigurationManager.ConnectionStrings[
"MoviesConnectionString"].ToString());
this.GridView1.DataSource = dc.Movies;
this.GridView1.DataBind();
this.BindDropDowList();
![](https://ucc.alicdn.com/notfound.png?x-oss-process=image/resize,w_1400/format,webp)
}
![](https://ucc.alicdn.com/notfound.png?x-oss-process=image/resize,w_1400/format,webp)
}
protected
void Button1_Click(
object sender, EventArgs e)
![](https://ucc.alicdn.com/notfound.png?x-oss-process=image/resize,w_1400/format,webp)
{
![](https://ucc.alicdn.com/notfound.png?x-oss-process=image/resize,w_1400/format,webp)
IQueryable<Movy> Iquery=
null;
int id =
int.Parse(DropDownList1.SelectedValue);
switch (id)
![](https://ucc.alicdn.com/notfound.png?x-oss-process=image/resize,w_1400/format,webp)
{
case -1:
![](https://ucc.alicdn.com/notfound.png?x-oss-process=image/resize,w_1400/format,webp)
Iquery = from movie
in
new DataClassesDataContext().Movies select movie;
break;
default:
![](https://ucc.alicdn.com/notfound.png?x-oss-process=image/resize,w_1400/format,webp)
Iquery = from movie
in
new DataClassesDataContext().Movies
![](https://ucc.alicdn.com/notfound.png?x-oss-process=image/resize,w_1400/format,webp)
where movie.ID == id
![](https://ucc.alicdn.com/notfound.png?x-oss-process=image/resize,w_1400/format,webp)
select movie;
break;
![](https://ucc.alicdn.com/notfound.png?x-oss-process=image/resize,w_1400/format,webp)
}
this.GridView1.DataSource = Iquery;
this.GridView1.DataBind();
![](https://ucc.alicdn.com/notfound.png?x-oss-process=image/resize,w_1400/format,webp)
}
protected
void BindDropDowList()
![](https://ucc.alicdn.com/notfound.png?x-oss-process=image/resize,w_1400/format,webp)
{
![](https://ucc.alicdn.com/notfound.png?x-oss-process=image/resize,w_1400/format,webp)
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"));
![](https://ucc.alicdn.com/notfound.png?x-oss-process=image/resize,w_1400/format,webp)
}
protected
void GridView1_RowDataBound(
object sender, GridViewRowEventArgs e)
![](https://ucc.alicdn.com/notfound.png?x-oss-process=image/resize,w_1400/format,webp)
{
if (e.Row.RowType == DataControlRowType.DataRow)
![](https://ucc.alicdn.com/notfound.png?x-oss-process=image/resize,w_1400/format,webp)
{
![](https://ucc.alicdn.com/notfound.png?x-oss-process=image/resize,w_1400/format,webp)
e.Row.Attributes.Add(
"onMouseOver",
"SetNewColor(this);");
![](https://ucc.alicdn.com/notfound.png?x-oss-process=image/resize,w_1400/format,webp)
e.Row.Attributes.Add(
"onMouseOut",
"SetOldColor(this);");
![](https://ucc.alicdn.com/notfound.png?x-oss-process=image/resize,w_1400/format,webp)
}
![](https://ucc.alicdn.com/notfound.png?x-oss-process=image/resize,w_1400/format,webp)
}
![](https://ucc.alicdn.com/notfound.png?x-oss-process=image/resize,w_1400/format,webp)
}