日期:2014-05-17  浏览次数:20488 次

asp.net中TreeView的使用
刚做的一个小功能,就是在asp.net中实现TreeView与数据库的绑定,输出多级节点的数据,求助各位高手!

------解决方案--------------------
http://www.cnblogs.com/wdx2008/archive/2007/06/22/792509.html
------解决方案--------------------
DataSet datasetMenu = ado.ExecuteGet (sqlFunction);//查询

//string sMname = datasetMenu.Tables[0].Rows[0]["modulename"].ToString ();
string sMname="";
TreeNode nodeRoleName = new TreeNode();
nodeRoleName.Text = roleName;

/**
foreach(DataRow datarow in datasetMenu.Tables[0].Rows )
{
if( !sMname.Equals ( datarow["modulename"].ToString () ) )
{
Response.Write("<img src=images/line_1.gif align=absMiddle>" );
Response.Write("<IMG height=16 src=images/folder1.gif width=16 align=absMiddle>");
Response.Write("&nbsp;");
Response.Write(datarow["modulename"].ToString ());
Response.Write("<BR>");

sMname = datarow["modulename"].ToString ();

Response.Write("<IMG src=images/line_2.gif align=absMiddle border=0>");
Response.Write("<A href="+datarow["funcpath"].ToString ()+">");
Response.Write(datarow["functionname"].ToString ());
Response.Write("</A><br>");
}
else
{
Response.Write("<IMG src=images/line_2.gif align=absMiddle border=0>");
Response.Write("<A href="+datarow["funcpath"].ToString ()+">");
Response.Write(datarow["functionname"].ToString ());
Response.Write("</A><br>");
}
}**/

TreeNode nodeModule = new TreeNode();
TreeNode nodeFunction;
foreach(DataRow datarow in datasetMenu.Tables[0].Rows )
{
if( !sMname.Equals ( datarow["modulename"].ToString () ) )
{
if( nodeModule.Nodes .Count >0 ) nodeRoleName.Nodes .Add(nodeModule);

nodeModule = new TreeNode();
nodeModule.Text = datarow["modulename"].ToString ();

nodeFunction = new TreeNode();
nodeFunction.Text = datarow["functionname"].ToString ();
nodeFunction.NavigateUrl=virtualPath+datarow["funcpath"].ToString ();
nodeFunction.Target ="ifm";

nodeModule.Nodes.Add(nodeFunction);
//********************折叠树控件
nodeModule.Expanded = false;

sMname = datarow["modulename"].ToString ();


}
else
{
nodeFunction = new TreeNode();
nodeFunction.Text = datarow["functionname"].ToString ();
nodeFunction.NavigateUrl=virtualPath+datarow["funcpath"].ToString ();
nodeFunction.Target ="ifm";

nodeModule.Nodes.Add(nodeFunction);
}
}

//add the last module
nodeRoleName.Nodes .Add(nodeModule);

TreeView1.Nodes .Add ( nodeRoleName );