作者:http://www.aspcn.com 飞刀
上一节中,由于XML文件占了很大的篇幅,只好把源程序贴在这一页了。
也是很长的哟,大家有性子看才行:)
<% @ Page Language="C#" ResponseEncoding="gb2312" %>
<% @ Import Namespace="System.Data" %>
<% @ Import Namespace="System.Xml" %>
<% @ Import Namespace="System.IO" %>
<Script Language="C#" Runat="Server">
DataSet ds; //定义公用的DataSet
DataView dv; //定义公用的DataView
string SortField;
string sPath;
public void Page_Load(Object src,EventArgs e)
{
if(State["adxml"]==null)
{
sPath = Server.MapPath(".") + "\\AdBanners\\ad_gb.xml";
ds = new DataSet();
ds.ReadXml(sPath);
State["adxml"] = ds;
}
else
{
ds = (DataSet)State["adxml"];
}
dv = ds.Tables[0].DefaultView;
dv.Sort = "ImageUrl";
if(!Page.IsPostBack)
{
CreateTable();
}
}
//捆绑Binder
public void CreateTable()
{
dgXML.DataSource = dv;
dgXML.DataBind();
}
//翻页时
public void dgXML_Changed(Object sender,DataGridPageChangedEventArgs e)
{
CreateTable();
}
//删除
public void DelItem(Object sender,DataGridCommandEventArgs e)
{
if(((LinkButton)e.CommandSource).CommandName == "del")
{
//首先取得当前更新页的行数与CurrentPageIndex
int CPI = (int)dgXML.CurrentPageIndex;
int EII = (int)e.Item.ItemIndex;
int row = CPI*5+EII;
lb.Text = row.ToString();
//删除
dv.Delete(row);
dgXML.EditItemIndex = -1;
ds.WriteXml(sPath);
CreateTable();
}
}
//取消
public void dgXML_Cancel(Object sender,DataGridCommandEventArgs e)
{
dgXML.EditItemIndex = -1;
CreateTable();
}
//编辑
public void dgXML_Edit(Object sender,DataGridCommandEventArgs e)
{
dgXML.EditItemIndex = (int)e.Item.ItemIndex;
CreateTable();
}
//更新
public void dgXML_Update(Object sender, DataGridCommandEventArgs e)
{
try
{
//首先取得当前更新页的行数与CurrentPageIndex
int CPI = (int)dgXML.CurrentPageIndex;
int EII = (int)e.Item.ItemIndex;
int row = CPI*5+EII;
&n