📄 webform2.aspx.cs
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Xml.Xsl ;
using System.Xml.XPath ;
using System.IO ;
using System.Xml ;
using System.Data.SqlClient ;
namespace L31
{
/// <summary>
/// WebForm2 的摘要说明。
/// </summary>
public class WebForm2 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DataGrid DataGrid1;
protected System.Web.UI.WebControls.Xml Xml1;
private void Page_Load(object sender, System.EventArgs e)
{
////////////////////////////////////////
///在此处放置用户代码以初始化页面
///下面的代码示例加载一个 XSL 样式表,
///将一个称为 mydata.xml 的文件读入到 XPathDocument 中,
///并对一个称为 tyle_sheet.xslt 的文件
///上的数据执行转换,将格式化的输出发送到客户浏览器或者写入html文件
///////////////////////////////////
XslTransform xslt = new XslTransform();
Response.Write(MapPath("Style_sheet.xslt"));
xslt.Load(MapPath("Style_sheet.xslt"));
XPathDocument xpathdocument = new
XPathDocument(MapPath("Books.xml"));
//XmlTextWriter writer = new XmlTextWriter(Response.Output );
System.IO.StreamWriter sw=new StreamWriter(MapPath("test.html"));
XmlTextWriter writer = new XmlTextWriter(sw);
writer.Formatting=Formatting.Indented;
xslt.Transform(xpathdocument, null, writer, null);
sw.Close();
writer.Close();
////////////////////////////////////////
////
////将数据集写入xml文件
//////////////////
SqlConnection scon=
new SqlConnection("server=localhost;database=northwind;uid=sa;pwd=");
SqlDataAdapter sda=
new SqlDataAdapter("select top 5 * from orders",scon);
DataSet ds=new DataSet();
sda.Fill(ds);
ds.WriteXml (MapPath("test.xml"));
//////////////////////////////
///使用XmlDataDocument
/////////////////////////////
XmlDataDocument doc =new XmlDataDocument(ds);
this.Xml1.Document=doc;
doc.Save(MapPath("test2.xml"));
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -