本文介绍一下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文件的内容:
aspcn_bbs1.gifc
http://www.aspcn.com/bbs
ASPCN鎶?湳璁哄?/AlternateText>
bbs
50
aspcn_bbs3.gif
http://www.aspcn.com/bbs
ASPCN鎶?湳璁哄?/AlternateText>
bbs
50
aspcn_bbs2.gifc
http://www.aspcn.com/bbs
ASPCN鎶?湳璁哄?/AlternateText>
bbs2
50
http://www.aspcn.com/aspcn.gif
http://www.aspcn.com
鎴戞槸涓浗浜?/AlternateText>
涓浗浜?/Keyword>
80
http://www.aspcn.com/aspcn.gif
http://www.aspcn.com
鎴戞槸涓浗浜?/AlternateText>
涓浗浜?/Keyword>
80
http://www.aspcn.com/aspcn.gif
http://www.aspcn.com
鎴戞槸涓浗浜?/AlternateText>
涓浗浜?/Keyword>
80
http://www.aspcn.com/aspcn.gif
http://www.aspcn.com
鎴戞槸涓浗浜?/AlternateText>
涓浗浜?/Keyword>
80
http://www.aspcn.com/aspcn.gif
http://www.aspcn.com
鎴戞槸涓浗浜?/AlternateText>
涓浗浜?/Keyword>
80
http://www.aspcn.com/aspcn.gif
http://www.aspcn.com
鎴戞槸涓浗浜?/AlternateText>
涓浗浜?/Keyword>
80
http://www.aspcn.com/aspcn.gif
http://www.aspcn.com
鎴戞槸涓浗浜?/AlternateText>
涓浗浜?/Keyword>
80
http://www.aspcn.com/aspcn.gif
http://www.aspcn.com
鎴戞槸涓浗浜?/AlternateText>
涓浗浜?/Keyword>
80
http://www.aspcn.com/aspcn.gif
http://www.aspcn.com
鎴戞槸涓浗浜?/AlternateText>
涓浗浜?/Keyword>
80
http://www.aspcn.com/aspcn.gif
http://www.aspcn.com
鎴戞槸涓浗浜篸ddd
涓浗浜篸dd
98090
http://www.aspcn.com/aspcn.gif
鎴戞槸涓浗浜篴sdfasfad
涓浗浜篸dd
98090
http://wwwaspcn.com
http://
中文有点问题,但是在下面的程序中可以正常显示的,因为用了国际化技术,哈哈,这个例子用的东东可不少哟:)
这是Adrotator控件引用的标准格式XML。
我们先来看看程序的最后的显示结果是什么

由于XML文件占了很大的篇幅,只好把源程序贴在这一页了。
也是很长的哟,大家有性子看才行:)
AllowPaging="True"
PageSize="10"
BorderColor="black"
BorderWidth="1"
CellPadding="3"
Font-Name="Verdana"
Font-Size="8pt"
HeaderStyle-BackColor="#aaaadd"
PagerStyle-Mode="NumericPages"
PagerStyle-HorizontalAlign="Right"
PagerStyle-PrevPageText="前页"
PagerStyle-NextPageText="后页"
OnPageIndexChanged="dgXML_Changed"
OnEditCommand="dgXML_Edit"
OnCancelCommand="dgXML_Cancel"
OnUpdateCommand="dgXML_Update"
OnItemCommand="DelItem"
AutoGenerateColumns="false"
>
添加新的广告页面
广告图片URL:
广告链接地址:
图片说明:
广告所属类别:
显示时间
大家好好分析吧,飞刀要去睡觉啦。天天累成这样子,人都瘦了好多,我好心疼啊......(完)

