http://www.lybh.com/s/TreeViewDataSet.aspx 点击加号出现错误(100分)
http://www.lybh.com/s/TreeViewDataSet.aspx
怀疑是数据库部分写有错误。
源代码两个:
1.TreeViewDataSet.aspx
<%@ Import Namespace="Microsoft.Web.UI.WebControls" %>
<%@ Register TagPrefix="IE" Namespace="Microsoft.Web.UI.WebControls"
Assembly ="Microsoft.Web.UI.WebControls" %>
<html>
<head><title>TreeViewDataSet.aspx</title></head>
<body>
<form runat="Server">
<IE:TreeView
AutoPostBack="True"
TreeNodeSrc="Categories.aspx"
Runat="Server" />
</form>
</body>
</html>
2.Categories.aspx
<%@ Page Language="C#"%>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<script runat="server">
void Page_Load(Object sender, EventArgs e){
SqlConnection conNorthwind;
SqlCommand cmdCategories;
DataSet dstCategories;
string strQuery;
conNorthwind = new SqlConnection("Server=localhost;UID=sa;PWD=weiYI10!;Database=Northwind");
strQuery = "select CategoryName As Text, 'products.aspx?catid=' + LTRIM( STR( CategoryID ) ) " + "As TreeNodeSrc from Categories As TreeNode for xml auto, XMLDATA";
cmdCategories = new SqlCommand(strQuery, conNorthwind);
conNorthwind.Open();
dstCategories = new DataSet();
dstCategories.ReadXml(cmdCategories.ExecuteXmlReader(), XmlReadMode.Fragment);
dstCategories.DataSetName = "TREENODES";
dstCategories.WriteXml(Response.OutputStream);
conNorthwind.Close();
}
</script>