用ASP.
NET结合XML制作广告管理程序
本文介绍一下ASP.Net中对XML的用法,这里飞刀我只是展现了XML与DataSet相结合的用法。其实ASP.Net对XML的操作的方法与对象是很多的,比如XmlDataDocument,XmlTextReader等,这些对象功能很全,也很实用。
本文以Adrotator控件使用的XML为例(新手可以先看一下Adrotator控件的用法),写出了一个广告管理程序。这个程序,飞刀用到的控件主要是DataGrid,可以说已经用到了DataGrid几乎全部功能,大家在关注XML的同时,可以同时学到DataGrid使用方法。
先将本例中使用的一些方法对大家说明一下:
DataSet主要是使用的ReadXml与WriteXml方法。它们的功能看名字就知道了,飞刀也不罗嗦了。
DataGrid中使用的了很多的方法和对象。比如分页使用AllowPaging属性,排序使用AllowSorting属性,本例中使用了所有DataGrid中的事件,比如OnItemCommand,OnEditCommand,OnCancelCommand,OnUpdateCommand等。
大家认真查看这些事件的处理。
另外大家在看程序时,再想想,如果这个程序使用ASP来写需要多少页,呵呵,用ASP.Net只需要一页,而且无限次使用,这就是ASP.Net的优点。
程序中飞刀我做了些简单的注释,最重要的还是大家的理解。呵呵,最近我们
工作室的人是忙得一踏糊涂,所以就请大家原谅啦。飞刀这些日子不是不写程序,只是写的程序都需要发表在书上,(比如和追捕
软件一样功能的Web网页啦,真的可以实现与追捕一样的功能,绝无虚假)不能贴在网上啦。这样会被骂的:)
先看看我们操作的XML文件的内容:
xmlns:xsd="w3.org/1999/XMLSchema"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
aspcn_bbs1.gifc
aspcn/bbs
ASPCN技术论坛/AlternateText>
bbs
50
aspcn_bbs3.gif
aspcn/bbs
lternateText>ASPCN技术论坛/AlternateText>
bbs
50
aspcn_bbs2.gifc
aspcn/bbs
ASPCN技术论坛/AlternateText>
bbs2
50
aspcn/aspcn.gif
aspcn
我是中国人/AlternateText>
中国人/Keyword>
80
aspcn/aspcn.gif
aspcn
我是中国人/AlternateText>
中国人/Keyword>
80
aspcn/aspcn.gif
aspcn
我是中国人/AlternateText>
中国人/Keyword>
80
aspcn/aspcn.gif
aspcn
我是中国人/AlternateText>
中国人/Keyword>
80
aspcn/aspcn.gif
aspcn
我是中国人/AlternateText>
中国人/Keyword>
80
aspcn/aspcn.gif
aspcn
我是中国人/AlternateText>
中国人/Keyword>
80
aspcn/aspcn.gif
aspcn
我是中国人/AlternateText>
中国人/Keyword>
80
aspcn/aspcn.gif
aspcn
我是中国人/AlternateText>
中国人/Keyword>
80
aspcn/aspcn.gif
aspcn
我是中国人/AlternateText>
中国人/Keyword>
80
aspcn/aspcn.gif
aspcn
aaaddd
aaadd
98090
aspcn/aspcn.gif
aaasdfasfad
aaadd
98090
wwwaspcn
中文有点
问题,但是在下面的程序中可以正常显示
的,因为用了国际化技术,哈哈,这个例子用的东东可不少哟:
这是Adrotator控件引用的标准格式XML。
我们再来看看ASP.Net的
源代码:
由于XML文件占了很大的篇幅,只好把源程序贴在这一页了。(也是很长的哟,大家有性子看才行)
<% @ Page Language="C#" ResponseEncoding="gb2312" %>
<% @ Import Namespace="System.Data" %>
<% @ Import Namespace="System.Xml" %>
<% @ Import Namespace="System.IO" %>