asp.ner 本想让XML内容在表格中循环输出,但做不到。 求Label.Text循环输出的本法或自动生成动态表格的办法
程序代码:
using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Xml; using System.Xml.XPath; public partial class _Default : System.Web.UI.Page { public string[] x = new string[7]; protected void Page_Load(object sender, EventArgs e) { XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(Server.MapPath("x1.xml"));//你的xml文件 XmlNodeList xmlList = xmlDoc.SelectSingleNode("bookshelf").ChildNodes; for (int i = 0; i < xmlList.Count;i++ ) { foreach (XmlNode xmlNo in xmlList.Item(i)) { XmlElement xe = (XmlElement)xmlNo; { if (xe.Name == "name") { x[0] = xe.InnerText; } if (xe.Name == "author") { x[1] = xe.InnerText; } if (xe.Name == "company") { x[2] = xe.InnerText; } if (xe.Name == "type") { x[3] = xe.InnerText; } if (xe.Name == "intro") { x[4] = xe.InnerText; } if (xe.Name == "danjia") { x[5] = xe.InnerText; } } } Response.Write(x[0]+"<br>"); Response.Write(x[1] + "<br>"); Response.Write(x[2] + "<br>"); Response.Write(x[3] + "<br>"); Response.Write(x[4] + "<br>"); Response.Write(x[5] + "<br>"); //Label1.Text = x[0]; //Label2.Text = x[1]; //Label3.Text = x[2]; //Label4.Text = x[3]; //Label5.Text = x[4]; //Label6.Text = x[5]; } } }[local]1[/local] 本想让XML内容在表格中循环输出,但做不到。 求Label.Text循环输出的本法或自动生成动态表格的办法