xml保存图片和读取图片(二)

3.ImageList.aspx

None.gif <% @ Page language = " c# "  Codebehind = " ImageList.aspx.cs "  AutoEventWireup = " false "  Inherits = " WebForm_Question2.ImageList "   %>
None.gif
<! DOCTYPE HTML PUBLIC  " -//W3C//DTD HTML 4.0 Transitional//EN "   >
None.gif
< HTML >
None.gif    
< HEAD >
None.gif        
< title > ImageList </ title >
None.gif        
< meta name = " GENERATOR "  Content = " Microsoft Visual Studio .NET 7.1 " >
None.gif        
< meta name = " CODE_LANGUAGE "  Content = " C# " >
None.gif        
< meta name = " vs_defaultClientScript "  content = " JavaScript " >
None.gif        
< meta name = " vs_targetSchema "  content = " http://schemas.microsoft.com/intellisense/ie5 " >
None.gif    
</ HEAD >
None.gif    
< body MS_POSITIONING = " GridLayout " >
None.gif        
< form id = " Form1 "  method = " post "  runat = " server " >
None.gif            
< TABLE id = " Table1 "  style = " Z-INDEX: 102; LEFT: 152px; WIDTH: 694px; POSITION: absolute; TOP: 16px; HEIGHT: 240px "
None.gif                cellSpacing
= " 1 "  cellPadding = " 1 "  width = " 694 "  border = " 1 " >
None.gif                
< TR >
None.gif                    
< TD align = " center "  style = " HEIGHT: 34px " >
None.gif                        
< asp:Label id = " Label1 "  runat = " server "  Width = " 128px "  ForeColor = " #000040 "  Font - Bold = " True "  Font - Size = " Larger " > 图片列表页面 </ asp:Label ></ TD >
None.gif                
</ TR >
None.gif                
< TR >
None.gif                    
< TD style = " HEIGHT: 155px " >
None.gif                        
< asp:DataGrid id = " DG_ImageList "  runat = " server "  AutoGenerateColumns = " False "  Width = " 672px "  BorderColor = " #CCCCCC "
None.gif                            BorderStyle
= " None "  BorderWidth = " 1px "  BackColor = " White "  CellPadding = " 3 "  Height = " 144px "  AllowSorting = " True "
None.gif                            AllowPaging
= " True "  PageSize = " 5 " >
None.gif                            
< FooterStyle ForeColor = " #000066 "  BackColor = " White " ></ FooterStyle >
None.gif                            
< SelectedItemStyle Font - Bold = " True "  ForeColor = " White "  BackColor = " #669999 " ></ SelectedItemStyle >
None.gif                            
< ItemStyle ForeColor = " #000066 " ></ ItemStyle >
None.gif                            
< HeaderStyle Font - Bold = " True "  ForeColor = " White "  BackColor = " #006699 " ></ HeaderStyle >
None.gif                            
< Columns >
None.gif                                
< asp:BoundColumn DataField = " imageID "  HeaderText = " 图片ID " ></ asp:BoundColumn >
None.gif                                
< asp:BoundColumn DataField = " imagepath "  HeaderText = " 图片路径 " ></ asp:BoundColumn >
None.gif                                
< asp:BoundColumn DataField = " imageinfo "  HeaderText = " 图片说明 " ></ asp:BoundColumn >
None.gif                                
< asp:BoundColumn DataField = " imagesize "  SortExpression = " imagesize "  HeaderText = " 图片大小 " ></ asp:BoundColumn >
None.gif                                
< asp:TemplateColumn >
None.gif                                    
< ItemTemplate >
None.gif                                        
< a href = ' ImageDisplay.aspx?imageID=<%# DataBinder.Eval(Container.DataItem,"imageID")%> ' >
None.gif                                            查看
</ a >
None.gif                                    
</ ItemTemplate >
None.gif                                
</ asp:TemplateColumn >
None.gif                            
</ Columns >
None.gif                            
< PagerStyle HorizontalAlign = " Left "  ForeColor = " #000066 "  BackColor = " White "  Mode = " NumericPages " ></ PagerStyle >
None.gif                        
</ asp:DataGrid ></ TD >
None.gif                
</ TR >
None.gif                
< TR >
None.gif                    
< TD >< FONT face = " 宋体 " >
None.gif                            
< 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;
None.gif                            
< asp:HyperLink id = " HyperLink1 "  runat = " server "  NavigateUrl = " ImageList.xml " > 查看XMl文件 </ asp:HyperLink >
None.gif                        
</ FONT >
None.gif                    
</ TD >
None.gif                
</ TR >
None.gif            
</ TABLE >
None.gif        
</ form >
None.gif    
</ body >
None.gif
</ HTML >
None.gif
4.ImageList.aspx.cs
None.gif using  System;
None.gif
using  System.Collections;
None.gif
using  System.ComponentModel;
None.gif
using  System.Data;
None.gif
using  System.Drawing;
None.gif
using  System.Web;
None.gif
using  System.Web.SessionState;
None.gif
using  System.Web.UI;
None.gif
using  System.Web.UI.WebControls;
None.gif
using  System.Web.UI.HtmlControls;
None.gif
None.gif
namespace  WebForm_Question2
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
ExpandedSubBlockStart.gifContractedSubBlock.gif    
/**//// <summary>
InBlock.gif    
/// ImageList 的摘要说明。
ExpandedSubBlockEnd.gif    
/// </summary>

InBlock.gif    public class ImageList : System.Web.UI.Page
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
protected System.Web.UI.WebControls.Label Label1;
InBlock.gif        
protected System.Web.UI.WebControls.HyperLink HyperLink2;
InBlock.gif        
protected System.Web.UI.WebControls.HyperLink HyperLink1;
InBlock.gif        
protected System.Web.UI.WebControls.DataGrid DG_ImageList;
InBlock.gif    
InBlock.gif        
private void Page_Load(object sender, System.EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
// 在此处放置用户代码以初始化页面
InBlock.gif
            if(!IsPostBack)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                ViewState[
"SortField"= "imagesize"//默认排序字段
InBlock.gif
                BindDG();
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif        
Web 窗体设计器生成的代码#region Web 窗体设计器生成的代码
InBlock.gif        
override protected void OnInit(EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
//
InBlock.gif            
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
InBlock.gif            
//
InBlock.gif
            InitializeComponent();
InBlock.gif            
base.OnInit(e);
ExpandedSubBlockEnd.gif        }

InBlock.gif        
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
InBlock.gif        
/// 此方法的内容。
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        private void InitializeComponent()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{    
InBlock.gif            
this.DG_ImageList.PageIndexChanged += new System.Web.UI.WebControls.DataGridPageChangedEventHandler(this.DG_ImageList_PageIndexChanged);
InBlock.gif            
this.DG_ImageList.ItemDataBound += new System.Web.UI.WebControls.DataGridItemEventHandler(this.DG_ImageList_ItemDataBound);
InBlock.gif            
this.DG_ImageList.SortCommand += new System.Web.UI.WebControls.DataGridSortCommandEventHandler(this.DataGrid_Sort);
InBlock.gif            
this.Load += new System.EventHandler(this.Page_Load);
InBlock.gif
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif        
#endregion

ContractedSubBlock.gifExpandedSubBlockStart.gif        
将ImageList.xml文件绑定DataGrid中#region 将ImageList.xml文件绑定DataGrid中
InBlock.gif        
private void BindDG()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            DataSet ds 
= new DataSet();
InBlock.gif            ds.ReadXml(Server.MapPath(
"ImageList.xml"));
InBlock.gif
InBlock.gif            DataView dv 
= (DataView)ds.Tables[0].DefaultView; 
InBlock.gif           
InBlock.gif            
//设置排序的表达式
InBlock.gif
            dv.Sort = SortField;
InBlock.gif            
if (!SortAscending)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
//定义默认的排序表达式
InBlock.gif
                dv.Sort += " DESC";    
ExpandedSubBlockEnd.gif            }

InBlock.gif
InBlock.gif            
this.DG_ImageList.DataSource = ds.Tables[0];
InBlock.gif            
this.DG_ImageList.DataBind();
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif        
#endregion

ContractedSubBlock.gifExpandedSubBlockStart.gif        
排序事件处理程序#region 排序事件处理程序
InBlock.gif        
public void DataGrid_Sort(Object sender,DataGridSortCommandEventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
//对DataGrid排序
InBlock.gif
            this.DG_ImageList.CurrentPageIndex = 0;
InBlock.gif            SortField 
= e.SortExpression;
InBlock.gif
InBlock.gif            BindDG(); 
//重新绑定数据
ExpandedSubBlockEnd.gif
        }

InBlock.gif        
string SortField
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get 
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
object obj = ViewState["SortField"];
InBlock.gif                
if (obj == null
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
return String.Empty;
ExpandedSubBlockEnd.gif                }

InBlock.gif                
return (string)obj;
ExpandedSubBlockEnd.gif            }

InBlock.gif
InBlock.gif            
set 
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
if (value == SortField) 
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    SortAscending 
= !SortAscending;
ExpandedSubBlockEnd.gif                }

InBlock.gif                ViewState[
"SortField"= value;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
//排序方式
InBlock.gif
        bool SortAscending 
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get 
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
object obj = ViewState["SortAscending"];
InBlock.gif                
if (obj == null
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
return true;
ExpandedSubBlockEnd.gif                }

InBlock.gif                
return (bool)obj;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
set 
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{   
InBlock.gif                ViewState[
"SortAscending"= value;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif    
ExpandedSubBlockEnd.gif        
#endregion

ContractedSubBlock.gifExpandedSubBlockStart.gif        
DataGrid分页事件#region DataGrid分页事件
InBlock.gif        
private void DG_ImageList_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
this.DG_ImageList.CurrentPageIndex = e.NewPageIndex;
InBlock.gif            BindDG();
InBlock.gif
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif        
#endregion

ContractedSubBlock.gifExpandedSubBlockStart.gif        
鼠标经过事件#region 鼠标经过事件
InBlock.gif        
private void DG_ImageList_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
if ((e.Item.ItemType == ListItemType.Item) |  (e.Item.ItemType == ListItemType.AlternatingItem) )
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                 e.Item.Attributes.Add(
"onmouseover""this.style.backgroundColor='#E4EDF9'");
InBlock.gif                 e.Item.Attributes.Add(
"onmouseout""this.style.backgroundColor='#ffffff'");
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif        
#endregion

ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}

None.gif

转载于:https://www.cnblogs.com/tenghoo/archive/2006/09/18/507038.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值