自己写树控件。
用微软的和非微软的控件头都搞大的。有相当一部分功能不能实现。或者功能起来复杂。
以前没写过控件,刚好学习学习写自己的控件。
求过来人指点。
求思路。
[解决办法]
JS Tree参考~*************************************************
本内容使用CSDN小秘书回复
每天回帖即可得10分可用分!
*************************************************
[解决办法]
路过帮顶!!!
建议你看看《庖丁解牛:纵向切入ASP.NET3.5控件和组件开发技术》
[解决办法]
http://blog.csdn.net/ChengKing/category/288694.aspx
这是作者的博客、
[解决办法]
这是我自己写的 你可以参考一下 他是不用控件做的
控件是知其然,不知其所以然[code=VB.NET][/code]
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using LinkDataDALTableAdapters;
public partial class linkData_Default3 : System.Web.UI.Page
{
DeptTableAdapter _DeptTableAdapter = new DeptTableAdapter();
SpecialtyTableAdapter _SpecialtyTableAdapter = new SpecialtyTableAdapter();
ClassTableAdapter _ClassTableAdapter = new ClassTableAdapter();
StudentTableAdapter _StudentTableAdapter = new StudentTableAdapter();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
CreateTree();
}
private void CreateTree()
{
DataTable myTable1 = _DeptTableAdapter.GetData();
for (int i = 0; i < myTable1.Rows.Count; i++)
{
TreeNode node1;
node1 = new TreeNode(myTable1.Rows[i][1].ToString(), myTable1.Rows[i][0].ToString());//法政系
TreeView1.Nodes.Add(node1);
DataTable myTable2 = _SpecialtyTableAdapter.GetDataByDeptId(Convert.ToInt16(myTable1.Rows[i][0]));
for (int j = 0; j < myTable2.Rows.Count; j++)
{
TreeNode node2;
node2 = new TreeNode(myTable2.Rows[j][1].ToString(), myTable2.Rows[j][0].ToString());
node1.ChildNodes.Add(node2);
DataTable myTable3 = _ClassTableAdapter.GetDataBySid(Convert.ToInt16(myTable2.Rows[j][0]));
for (int k = 0; k < myTable3.Rows.Count; k++)
{
TreeNode node3;
node3 = new TreeNode(myTable3.Rows[k][1].ToString(), myTable3.Rows[k][0].ToString());
node2.ChildNodes.Add(node3);
}
}
}
}
protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e)
{
string a = TreeView1.ExpandDepth.ToString();
Response.Write(a);
}
}
[解决办法]
treeivew
还有codeproject
[解决办法]
public partial class LeftTreeView : System.Web.UI.Page
{
protected DataTable dataTbl1, dataTbl2;
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
string wherstr="";
if (Request.Cookies["Username"].Value.ToString().ToLower () == "admin" && Request.Cookies["Password"].Value.ToString() == "1")
{
wherstr = "";
}
else
{
if (Session["RoleId"] != null)
{
string roleid = Session["RoleId"].ToString();
wherstr = " where page_id in(select page_id from RolePageRelationship where Role_id=" + roleid + ")";
}
}
InitRootNodeDataTable(wherstr);
initTree(dataTbl1);
//tvCategory.CollapseAll();
}
}
/// <summary>
/// 初始化 RootNode DataTable
/// </summary>
private void InitRootNodeDataTable(string wherstr)
{
dataTbl1 = new DataTable();
dataTbl1 = DbAccess.GetDS("select * from page " + wherstr).Tables[0];
//读取并将公共的分类信息添加到数据集中
dataTbl1.TableName = "TreeView";
}
/// <summary>
/// 初始化树
/// </summary>
/// <param name="dt">取得所有的分类</param>
private void initTree(DataTable dt)
{
this.tvCategory.Nodes.Clear();//先清理原先的
if (dt != null && dt.Rows.Count == 0) return;
DataRow[] Rows = dt.Select("Page_parent=0 ");
if (Rows.Length == 0) return;
foreach (DataRow row in Rows)
{
TreeNode tNode = new TreeNode();
tNode.Value = row["Page_id"].ToString();
tNode.Text = row["Page_name"].ToString();
//tNode.NavigateUrl = "";
//tNode.Target = "MainFrameBS";//指向父窗体右边的那个iframe
this.tvCategory.Nodes.Add(tNode);
tNode.Expanded = true;
createChildNode(tNode, tNode.Value);
}
////添加一级“未分类”节点
//TreeNode tNode1 = new TreeNode();
//tNode1.Value = "-1";
//tNode1.Text = "未分类";
//tNode1.NavigateUrl = "BasicInfoConfig.aspx?Class_ID=" + tNode1.Value + "";
//tNode1.Target = "MainFrameBS";//指向父窗体右边的那个iframe
//this.tvCategory.Nodes.Add(tNode1);
//tNode1.Expanded = true;
}
/// <summary>
/// 创建子节点
/// </summary>
/// <param name="node"></param>
/// <param name="strParentNo"></param>
private void createChildNode(TreeNode node, string strParentNo)
{
//string parentId="";
DataRow[] Rows = this.dataTbl1.Select("Page_parent='" + strParentNo + "' and Page_parent<>0");
foreach (DataRow row in Rows)
{
TreeNode childNode = new TreeNode();
childNode.Value = row["Page_id"].ToString();
childNode.Target = "mainFrame";//指向父窗体右边的那个iframe
childNode.Text = row["Page_name"].ToString();
childNode.NavigateUrl = "~/"+row["Page_url"].ToString(); ;
node.ChildNodes.Add(childNode);
createChildNode(childNode, row["Page_id"].ToString());
}
}
}
}
[解决办法]
前台
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="LeftTreeView.aspx.cs" Inherits="CN.Web.LeftTreeView" %>
<!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>jQuery UI Accordion - Fill space</title>
<LINK href="../resource/sit.css" type=text/css rel=stylesheet>
<link type="text/css" href="../resource/themes/custom-theme/jquery-ui-1.7.2.custom.css" rel="stylesheet" />
<script type="text/javascript" src="../js/jquery-1.3.2.js"></script>
<script type="text/javascript" src="../js/ui/ui.core.js"></script>
<script type="text/javascript" src="../js/ui/ui.resizable.js"></script>
<script type="text/javascript" src="../js/ui/ui.accordion.js"></script>
<link type="text/css" href="../resource/demos.css" rel="stylesheet" />
<link rel="StyleSheet" href="../resource/dtree.css" type="text/css" />
<script type="text/javascript" src="../js/dtree.js"></script>
<script type="text/javascript">
$(function() {
$("#accordion").accordion({
fillSpace: true
});
});
</script>
<link href="../../jquery-ui-1.7.2.custom.css" rel="stylesheet" type="text/css">
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TreeView ID="tvCategory" runat="server">
</asp:TreeView>
</div>
</form>
</body>
</html>
[解决办法]
可以看看这里的树。
http://demo.naturefw.com/login.aspx
风格选择“老版(frameset)”,登录后你就可以看到左面有一颗树。
这个是自己写的,没有封装,你可以参考一下。
点击这里
可以下载源码。
[解决办法]
学习阶段建议自己写控件,工作阶段建议优先考虑商业控件。
当手头Money不多时......
天真的很蓝 很蓝
[解决办法]
这个才牛