3.ImageList.aspx
<%
@ Page language
=
"
c#
"
Codebehind
=
"
ImageList.aspx.cs
"
AutoEventWireup
=
"
false
"
Inherits
=
"
WebForm_Question2.ImageList
"
%>
<! DOCTYPE HTML PUBLIC " -//W3C//DTD HTML 4.0 Transitional//EN " >
< HTML >
< HEAD >
< title > ImageList </ title >
< meta name = " GENERATOR " Content = " Microsoft Visual Studio .NET 7.1 " >
< meta name = " CODE_LANGUAGE " Content = " C# " >
< meta name = " vs_defaultClientScript " content = " JavaScript " >
< meta name = " vs_targetSchema " content = " http://schemas.microsoft.com/intellisense/ie5 " >
</ HEAD >
< body MS_POSITIONING = " GridLayout " >
< form id = " Form1 " method = " post " runat = " server " >
< TABLE id = " Table1 " style = " Z-INDEX: 102; LEFT: 152px; WIDTH: 694px; POSITION: absolute; TOP: 16px; HEIGHT: 240px "
cellSpacing = " 1 " cellPadding = " 1 " width = " 694 " border = " 1 " >
< TR >
< TD align = " center " style = " HEIGHT: 34px " >
< asp:Label id = " Label1 " runat = " server " Width = " 128px " ForeColor = " #000040 " Font - Bold = " True " Font - Size = " Larger " > 图片列表页面 </ asp:Label ></ TD >
</ TR >
< TR >
< TD style = " HEIGHT: 155px " >
< asp:DataGrid id = " DG_ImageList " runat = " server " AutoGenerateColumns = " False " Width = " 672px " BorderColor = " #CCCCCC "
BorderStyle = " None " BorderWidth = " 1px " BackColor = " White " CellPadding = " 3 " Height = " 144px " AllowSorting = " True "
AllowPaging = " True " PageSize = " 5 " >
< FooterStyle ForeColor = " #000066 " BackColor = " White " ></ FooterStyle >
< SelectedItemStyle Font - Bold = " True " ForeColor = " White " BackColor = " #669999 " ></ SelectedItemStyle >
< ItemStyle ForeColor = " #000066 " ></ ItemStyle >
< HeaderStyle Font - Bold = " True " ForeColor = " White " BackColor = " #006699 " ></ HeaderStyle >
< Columns >
< asp:BoundColumn DataField = " imageID " HeaderText = " 图片ID " ></ asp:BoundColumn >
< asp:BoundColumn DataField = " imagepath " HeaderText = " 图片路径 " ></ asp:BoundColumn >
< asp:BoundColumn DataField = " imageinfo " HeaderText = " 图片说明 " ></ asp:BoundColumn >
< asp:BoundColumn DataField = " imagesize " SortExpression = " imagesize " HeaderText = " 图片大小 " ></ asp:BoundColumn >
< asp:TemplateColumn >
< ItemTemplate >
< a href = ' ImageDisplay.aspx?imageID=<%# DataBinder.Eval(Container.DataItem,"imageID")%> ' >
查看 </ a >
</ ItemTemplate >
</ asp:TemplateColumn >
</ Columns >
< PagerStyle HorizontalAlign = " Left " ForeColor = " #000066 " BackColor = " White " Mode = " NumericPages " ></ PagerStyle >
</ asp:DataGrid ></ TD >
</ TR >
< TR >
< TD >< FONT face = " 宋体 " >
< asp:HyperLink id = " HyperLink2 " runat = " server " NavigateUrl = " index.aspx " > 主页面 </ asp:HyperLink >& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp;
< asp:HyperLink id = " HyperLink1 " runat = " server " NavigateUrl = " ImageList.xml " > 查看XMl文件 </ asp:HyperLink >
</ FONT >
</ TD >
</ TR >
</ TABLE >
</ form >
</ body >
</ HTML >
4.ImageList.aspx.cs<! DOCTYPE HTML PUBLIC " -//W3C//DTD HTML 4.0 Transitional//EN " >
< HTML >
< HEAD >
< title > ImageList </ title >
< meta name = " GENERATOR " Content = " Microsoft Visual Studio .NET 7.1 " >
< meta name = " CODE_LANGUAGE " Content = " C# " >
< meta name = " vs_defaultClientScript " content = " JavaScript " >
< meta name = " vs_targetSchema " content = " http://schemas.microsoft.com/intellisense/ie5 " >
</ HEAD >
< body MS_POSITIONING = " GridLayout " >
< form id = " Form1 " method = " post " runat = " server " >
< TABLE id = " Table1 " style = " Z-INDEX: 102; LEFT: 152px; WIDTH: 694px; POSITION: absolute; TOP: 16px; HEIGHT: 240px "
cellSpacing = " 1 " cellPadding = " 1 " width = " 694 " border = " 1 " >
< TR >
< TD align = " center " style = " HEIGHT: 34px " >
< asp:Label id = " Label1 " runat = " server " Width = " 128px " ForeColor = " #000040 " Font - Bold = " True " Font - Size = " Larger " > 图片列表页面 </ asp:Label ></ TD >
</ TR >
< TR >
< TD style = " HEIGHT: 155px " >
< asp:DataGrid id = " DG_ImageList " runat = " server " AutoGenerateColumns = " False " Width = " 672px " BorderColor = " #CCCCCC "
BorderStyle = " None " BorderWidth = " 1px " BackColor = " White " CellPadding = " 3 " Height = " 144px " AllowSorting = " True "
AllowPaging = " True " PageSize = " 5 " >
< FooterStyle ForeColor = " #000066 " BackColor = " White " ></ FooterStyle >
< SelectedItemStyle Font - Bold = " True " ForeColor = " White " BackColor = " #669999 " ></ SelectedItemStyle >
< ItemStyle ForeColor = " #000066 " ></ ItemStyle >
< HeaderStyle Font - Bold = " True " ForeColor = " White " BackColor = " #006699 " ></ HeaderStyle >
< Columns >
< asp:BoundColumn DataField = " imageID " HeaderText = " 图片ID " ></ asp:BoundColumn >
< asp:BoundColumn DataField = " imagepath " HeaderText = " 图片路径 " ></ asp:BoundColumn >
< asp:BoundColumn DataField = " imageinfo " HeaderText = " 图片说明 " ></ asp:BoundColumn >
< asp:BoundColumn DataField = " imagesize " SortExpression = " imagesize " HeaderText = " 图片大小 " ></ asp:BoundColumn >
< asp:TemplateColumn >
< ItemTemplate >
< a href = ' ImageDisplay.aspx?imageID=<%# DataBinder.Eval(Container.DataItem,"imageID")%> ' >
查看 </ a >
</ ItemTemplate >
</ asp:TemplateColumn >
</ Columns >
< PagerStyle HorizontalAlign = " Left " ForeColor = " #000066 " BackColor = " White " Mode = " NumericPages " ></ PagerStyle >
</ asp:DataGrid ></ TD >
</ TR >
< TR >
< TD >< FONT face = " 宋体 " >
< asp:HyperLink id = " HyperLink2 " runat = " server " NavigateUrl = " index.aspx " > 主页面 </ asp:HyperLink >& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp;
< asp:HyperLink id = " HyperLink1 " runat = " server " NavigateUrl = " ImageList.xml " > 查看XMl文件 </ asp:HyperLink >
</ FONT >
</ TD >
</ TR >
</ TABLE >
</ form >
</ body >
</ HTML >
using
System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace WebForm_Question2
{
/**//// <summary>
/// ImageList 的摘要说明。
/// </summary>
public class ImageList : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.HyperLink HyperLink2;
protected System.Web.UI.WebControls.HyperLink HyperLink1;
protected System.Web.UI.WebControls.DataGrid DG_ImageList;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
if(!IsPostBack)
{
ViewState["SortField"] = "imagesize"; //默认排序字段
BindDG();
}
}
Web 窗体设计器生成的代码#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/**//// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.DG_ImageList.PageIndexChanged += new System.Web.UI.WebControls.DataGridPageChangedEventHandler(this.DG_ImageList_PageIndexChanged);
this.DG_ImageList.ItemDataBound += new System.Web.UI.WebControls.DataGridItemEventHandler(this.DG_ImageList_ItemDataBound);
this.DG_ImageList.SortCommand += new System.Web.UI.WebControls.DataGridSortCommandEventHandler(this.DataGrid_Sort);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
将ImageList.xml文件绑定DataGrid中#region 将ImageList.xml文件绑定DataGrid中
private void BindDG()
{
DataSet ds = new DataSet();
ds.ReadXml(Server.MapPath("ImageList.xml"));
DataView dv = (DataView)ds.Tables[0].DefaultView;
//设置排序的表达式
dv.Sort = SortField;
if (!SortAscending)
{
//定义默认的排序表达式
dv.Sort += " DESC";
}
this.DG_ImageList.DataSource = ds.Tables[0];
this.DG_ImageList.DataBind();
}
#endregion
排序事件处理程序#region 排序事件处理程序
public void DataGrid_Sort(Object sender,DataGridSortCommandEventArgs e)
{
//对DataGrid排序
this.DG_ImageList.CurrentPageIndex = 0;
SortField = e.SortExpression;
BindDG(); //重新绑定数据
}
string SortField
{
get
{
object obj = ViewState["SortField"];
if (obj == null)
{
return String.Empty;
}
return (string)obj;
}
set
{
if (value == SortField)
{
SortAscending = !SortAscending;
}
ViewState["SortField"] = value;
}
}
//排序方式
bool SortAscending
{
get
{
object obj = ViewState["SortAscending"];
if (obj == null)
{
return true;
}
return (bool)obj;
}
set
{
ViewState["SortAscending"] = value;
}
}
#endregion
DataGrid分页事件#region DataGrid分页事件
private void DG_ImageList_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
this.DG_ImageList.CurrentPageIndex = e.NewPageIndex;
BindDG();
}
#endregion
鼠标经过事件#region 鼠标经过事件
private void DG_ImageList_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if ((e.Item.ItemType == ListItemType.Item) | (e.Item.ItemType == ListItemType.AlternatingItem) )
{
e.Item.Attributes.Add("onmouseover", "this.style.backgroundColor='#E4EDF9'");
e.Item.Attributes.Add("onmouseout", "this.style.backgroundColor='#ffffff'");
}
}
#endregion
}
}
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace WebForm_Question2
{
/**//// <summary>
/// ImageList 的摘要说明。
/// </summary>
public class ImageList : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.HyperLink HyperLink2;
protected System.Web.UI.WebControls.HyperLink HyperLink1;
protected System.Web.UI.WebControls.DataGrid DG_ImageList;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
if(!IsPostBack)
{
ViewState["SortField"] = "imagesize"; //默认排序字段
BindDG();
}
}
Web 窗体设计器生成的代码#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/**//// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.DG_ImageList.PageIndexChanged += new System.Web.UI.WebControls.DataGridPageChangedEventHandler(this.DG_ImageList_PageIndexChanged);
this.DG_ImageList.ItemDataBound += new System.Web.UI.WebControls.DataGridItemEventHandler(this.DG_ImageList_ItemDataBound);
this.DG_ImageList.SortCommand += new System.Web.UI.WebControls.DataGridSortCommandEventHandler(this.DataGrid_Sort);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
将ImageList.xml文件绑定DataGrid中#region 将ImageList.xml文件绑定DataGrid中
private void BindDG()
{
DataSet ds = new DataSet();
ds.ReadXml(Server.MapPath("ImageList.xml"));
DataView dv = (DataView)ds.Tables[0].DefaultView;
//设置排序的表达式
dv.Sort = SortField;
if (!SortAscending)
{
//定义默认的排序表达式
dv.Sort += " DESC";
}
this.DG_ImageList.DataSource = ds.Tables[0];
this.DG_ImageList.DataBind();
}
#endregion
排序事件处理程序#region 排序事件处理程序
public void DataGrid_Sort(Object sender,DataGridSortCommandEventArgs e)
{
//对DataGrid排序
this.DG_ImageList.CurrentPageIndex = 0;
SortField = e.SortExpression;
BindDG(); //重新绑定数据
}
string SortField
{
get
{
object obj = ViewState["SortField"];
if (obj == null)
{
return String.Empty;
}
return (string)obj;
}
set
{
if (value == SortField)
{
SortAscending = !SortAscending;
}
ViewState["SortField"] = value;
}
}
//排序方式
bool SortAscending
{
get
{
object obj = ViewState["SortAscending"];
if (obj == null)
{
return true;
}
return (bool)obj;
}
set
{
ViewState["SortAscending"] = value;
}
}
#endregion
DataGrid分页事件#region DataGrid分页事件
private void DG_ImageList_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
this.DG_ImageList.CurrentPageIndex = e.NewPageIndex;
BindDG();
}
#endregion
鼠标经过事件#region 鼠标经过事件
private void DG_ImageList_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if ((e.Item.ItemType == ListItemType.Item) | (e.Item.ItemType == ListItemType.AlternatingItem) )
{
e.Item.Attributes.Add("onmouseover", "this.style.backgroundColor='#E4EDF9'");
e.Item.Attributes.Add("onmouseout", "this.style.backgroundColor='#ffffff'");
}
}
#endregion
}
}