|
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
//Tree1 OnClientClick = TabStrip1.GetAddTabReference(e.Node.Text, "fa_zclb.aspx", e.Node.Text, IconHelper.GetIconUrl(Icon.Application), true));
LoadData();
}
}
private void LoadData()
{
var db = new DBClass();
//var dt = new DataTable();
var ds = new DataSet();
string sql = "select lbdm,lbmc,case when len(rtrim(lbdm))=2 then NULL else left(lbdm,2) end 'ParentID' ";
sql += "from FA_Gdlb where gsdm='@gsdm' order by lbdm";
sql = sql.Replace("@gsdm", RunContext.Dw.gsdm);
ds = db.ExecQueryRecordSet(sql, "fa_gdlb"); //返回 数据集
ds.Relations.Add("TreeRelation", ds.Tables[0].Columns["lbdm"], ds.Tables[0].Columns["ParentID"]);//
foreach (DataRow row in ds.Tables[0].Rows)
{
if (row.IsNull("ParentID")) //DBNull.Value
{ //上级代码为空时,表示一级节点
TreeNode node = new TreeNode();
node.Text = row["lbdm"].ToString() +" "+ row["lbmc"].ToString();
node.Expanded = true;//展开节点
//node.Leaf = false; //是否是叶子节点
node.NodeID = row["lbdm"].ToString();
Tree1.Nodes.Add(node);//增加 父节点
ResolveSubTree(row, node); //加载 子节点
}
}
}
private void ResolveSubTree(DataRow dataRow, TreeNode treeNode)
{
DataRow[] rows = dataRow.GetChildRows("TreeRelation");//从"关系名"行中读取"子节点"行集
if (rows.Length > 0) // 行集不为空
{
treeNode.Expanded = true;//展开节点
foreach (DataRow row in rows) //从 子节点 行集中读取.
{
TreeNode node = new TreeNode(); //创建空节点
node.NodeID = row["lbdm"].ToString();
node.Text = row["lbdm"].ToString() + " " + row["lbmc"].ToString();
node.EnablePostBack = false; //回发
node.OnClientClick = TabStrip1.GetAddTabReference(row["lbdm"].ToString(), "fa_zclb.aspx", row["lbmc"].ToString(), IconHelper.GetIconUrl(Icon.Application), true);
//TN.OnClientClick = TabStrip1.GetAddTabReference(dr["ID"].ToString(), dr["URL"].ToString() , dr["NAME"].ToString(), true);
//node.Leaf = true;
treeNode.Nodes.Add(node); //添加 二级 节点
//ResolveSubTree(row, node); // 读取 下级 节点
}
}
} |
|