现在的程序中用的Microsoft.Web.UI.WebControls.TreeView因为这个控件不标准不适合ff.chrome等。
所以我准备把它换成System.Web.UI.WebControls.TreeView,因为这个树的数据比较多。所以一次先加载第一层的数据。以后每点一个节点去加载它的子节点,找到一个jquery的例子。。直接用ajax不用jquery可以实现吗?http://topic.csdn.net/u/20110106/14/a4c9da4c-0930-436f-ab5b-0165ef878472.html
所以我准备把它换成System.Web.UI.WebControls.TreeView,因为这个树的数据比较多。所以一次先加载第一层的数据。以后每点一个节点去加载它的子节点,找到一个jquery的例子。。直接用ajax不用jquery可以实现吗?http://topic.csdn.net/u/20110106/14/a4c9da4c-0930-436f-ab5b-0165ef878472.html
为什么不用? 做起来也是个麻烦事情
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title></title>
<script language="javascript" src="../myTree/myTree.js"></script>
<script language="javascript" src="../myTree/bingo.js"></script>
<script language="javascript">
var tree;
window.onload = function(){
tree = new myTree("myFirstTree", "divTree", "../myTree/", "Blue");
tree.datafrom = "MyTreeGetNode.aspx"
tree.load();
}
function myFirstTree_onClick(prmNodeId){
tree.load(prmNodeId);
tree.expandNode(prmNodeId);
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div id="divTree"></div>
<div id="divStr"></div>
</form>
</body>
</html>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Text;
namespace VistaToNewSchol
{
public partial class MyTreeGetNode : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
int intId =-1;
if (Request.QueryString["parentId"] != null) //此处用parentId才能取的到值,应该是前台js为parentId赋的值,直接取出来就可以用了。
{
intId = Convert.ToInt32(Request.QueryString["parentId"].ToString());
}
string html = getNode(intId);
Response.Write(html);
Response.End();
}
}
//得到节点
public string getNode(int parentID)
{
string html = "";
StringBuilder strSql = new StringBuilder();
strSql.Append("select * ,(select count(metaId) from metadata where parentId=DB.metaId) AS SUBCOUNT ");
strSql.Append(" from dbo.metadata AS DB ");
strSql.Append(" where parentid=" + parentID + " ");
DataSet ds = VistaToNewSchol.DAL.DbHelperSQL.Query(strSql.ToString());
html += "[";
if (ds.Tables[0].Rows.Count > 0)
{
int count = 0;
foreach (DataRow row in ds.Tables[0].Rows)
{
if (count == 0)
{
}
else
{
html += ",";
}
html += "{";
html += "nodeId:'" + row["metaId"].ToString() + "',";
html += "caption:'" + row["metaName"].ToString() + "' ,";
html += "attach:{";
html += "subCount: '" + row["SUBCOUNT"].ToString() + "',";//子节点个数
html += "url:'#n' ";
html += "}";
html += "}";
count++;
}
}
html += "]";
return html;
}
}
}