|
private DataTable GetTable(int topid)
{
DataTable dt = null;
try
{
string constr = "server=.;database=tqnpc;uid=sa;pwd=sa";
string selstr = "select * from RW_工作關(guān)系 where main_id=" + topid + "";
SqlConnection con = new SqlConnection(constr);
SqlDataAdapter da = new SqlDataAdapter(selstr, con);
dt = new DataTable();
da.Fill(dt);
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
return dt;
}
protected void MakeTree()
{
DataTable dt = GetTable(0);
try
{
if (dt != null)
{
for (int i = 0; i < dt.Rows.Count; i++)
{
TreeNode tn = new TreeNode();
tn.Text = dt.Rows[i]["MAIN_ID"].ToString();
tn.Value = dt.Rows[i]["REF_ID"].ToString();
tn.SelectAction = TreeNodeSelectAction.Select;
TreeView1.Nodes.Add(tn);
AddTreeNodes(int.Parse(dt.Rows[i]["REF_ID"].ToString()), int.Parse(dt.Rows[i]["REF_ID"].ToString()), tn);
}
}
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
}
這個(gè)方法對(duì)數(shù)據(jù)庫的結(jié)構(gòu)也有一定的要求,數(shù)據(jù)庫的設(shè)計(jì)如下:
AspNet技術(shù):常用的在數(shù)據(jù)庫中建立無限級(jí)樹形菜單的asp.net代碼,轉(zhuǎn)載需保留來源!
鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請(qǐng)第一時(shí)間聯(lián)系我們修改或刪除,多謝。