TreeView无限节点
好久没有使用VS自带控件了,今天尝试在项目中用下TreeView功能全都写好了,放在服务器上后加载实在太慢,变改变思路,通过逐层进行加载,可是写好后发现无论如何点击第二节菜单时候总是展开第一节的菜单,哈哈,还是决定放弃这个控件年,问同行前辈猪二尚,给了我个JS折叠包,还是JS效果好。
如下是加载慢的项目源代码:
private void BindTree(string brand)
{
epic.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString2"].ConnectionString;
DataTable dt = new DataTable();
dt = epic.GetDataTable("select a2 from bearing where id in(Select min(id) FROM bearing group by a2) and a41='" + brand + "' ");
for (int i = 0; i < dt.Rows.Count; i++)
{
TreeNode tn = new TreeNode();
tn.Expanded = false;
tn.Text = dt.Rows[i]["a2"].ToString();
TreeView1.Nodes.Add(tn);
DataTable dt1 = new DataTable();
dt1 = epic.GetDataTable("Select a3 FROM bearing where a41='" + brand + "' and a2='" + dt.Rows[i]["a2"].ToString() + "' group by a3 ");
if (dt1.Rows.Count > 0)
{
for (int j = 0; j < dt1.Rows.Count; j++)
{
TreeNode tny = new TreeNode();
tny.Expanded = false;
tny.Text = dt1.Rows[j]["a3"].ToString();
tny.Value = "son";
tny.NavigateUrl = "THK_Xilie.aspx?cb=" + brand + "&cc=" + HttpUtility.UrlEncode(dt1.Rows[j]["a3"].ToString(), System.Text.Encoding.GetEncoding("GB2312"));
tn.ChildNodes.Add(tny);
this.LoadAddSign2(tny.ChildNodes, dt1.Rows[j]["a3"].ToString());//wsw更改
}
}
}
}
///
/// 用于加载显示 树形控件 +号的,加载下面的一个节点。
///
///
///
///
private void LoadAddSign2(TreeNodeCollection tn, string a3) //wsw更改
{
epic.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString2"].ConnectionString;
DataTable table = epic.GetDataTable("select a1,a4 from bearing where id in(Select min(id) FROM bearing where a41='THK' and a3='" + a3 + "' group by a4 )");
if (table.Rows.Count > 0)
{
//加载"一个"1级节点,就是为了显示 + 号
tn.Clear(); //清除之前加载的空节点。
if (table.Rows.Count > 0)
{
for (int i = 0; i < table.Rows.Count; i++)
{
TreeNode Node = new TreeNode();
Node.Text = table.Rows[i]["a4"].ToString();
Node.Value = "son_son";
Node.ToolTip = table.Rows[i]["a4"].ToString();
Node.NavigateUrl = "http://www.linears.cn/" + table.Rows[i]["a1"].ToString() + ".html";
tn.Add(Node);//增加父节点,这时直接往树TreeView1上加
}
}
}
}
最后附上折叠JS案例:
http://yunpan.cn/cKtMfqQU9vu9X 访问密码 c483