|
|
|
有关在 VC# 中的 WebXML 编程(2)http://www.sina.com.cn 2008年07月07日 17:28 《程序员》
using System.Xml; //处理XML必须加的Namespace,还需在References中加System.XML.Dll using System.IO; //读XML文件必须加的Namespace 然后在Page_Load中加入如下代码: protected void Page_Load(object sender, EventArgs e){ string datafile="guest.xml" ; //假设XML文件名为guest.xml StreamReader tyj=new StreamReader(Server.MapPath(datafile)); XmlDataDocument datadoc = new XmlDataDocument(); //创建该对象为了读取XML datadoc.DataSet.ReadXml(tyj); //读取guest.xml文件内容 DataGrid1.DataSource = datadoc.DataSet.Tables[0].DefaultView; //设置DataGrid数据源 DataGrid1.DataBind(); //绑定 datadoc=null ; //释放资源 tyj.Close();} //释放StreamReader类,这非常重要,否则下次打开会显示文件已经被使用 对应于显示用的Web Form中DataGrid的功能,我们需要增加下面的函数: protected void OnSelectName(object sender,EventArgs e) { Session["select_name"]=(string)DataGrid1.SelectedItem.Cells[1].Text.ToString(); //把选定的 DataGrid某行中的一个单元中的值(Name)存入一个会话变量中,以便下一页用 Response.Redirect("xml_manage.aspx");} //转到有增加删除功能的管理页 Web Form加入以下代码: <asp:DataGrid id=DataGrid1 runat="server" onselectedindexchanged="OnSelectName" > 代码中划线部分的作用是当按了“选择”按钮后,执行OnSelectName()中的程序,把选定的 DataGrid中某行中的一个单元中的值(Name)存入一个会话变量中,然后转到下一页。
【发表评论 】
不支持Flash
|