0
我有下面的代碼,我想把全局方法設置爲靜態,這樣我就可以在我的asp.net web應用程序上構建一對夫婦樹視圖。現在我使用下面的代碼構建自己的樹視圖。我正在考慮製作一個全局靜態方法來生成像這樣的節點結構,然後將它們分配給我的頁面中的樹形視圖......或類似的東西。我dotn關心實際解決方案的細節,只要我可以有一個方法調用像「buildTree()」,將能夠被用來綁定樹視圖控件。如何抽象樹視圖節點創建/填充?
艱難?
DataTable dtProjects = new DataTable();
DataTable dtRelease = new DataTable();
using (SqlConnection con = Global.GetConnection())
{
StringBuilder str = new StringBuilder();
str.Append("SELECT r.ReleaseId, ");
str.Append(" r.Name, ");
str.Append(" rs.EndDate ");
str.Append(" FROM Release r ");
str.Append(" LEFT OUTER JOIN ReleaseSchedule rs ");
str.Append(" ON r.ReleaseId = rs.ReleaseId ");
str.Append(" AND rs.MilestoneCID = 77");
str.Append(" WHERE r.CompletionStatusCID NOT IN (34, 35) ");
str.Append(" ORDER BY r.ReportingPriority, r.Name ");
SqlDataAdapter da = new SqlDataAdapter(str.ToString(), con);
da.Fill(dtRelease);
str = new StringBuilder();
str.Append("SELECT p.ProjectId, ");
str.Append(" p.ProjectName, ");
str.Append(" p.ParentProjectId, ");
str.Append(" p.ReleaseId ");
str.Append(" FROM Project p ");
str.Append(" WHERE p.CompletionStatusCID NOT IN (34, 35) ");
str.Append(" AND p.ProjectTypeCID <> 92 ");
str.Append(" ORDER BY p.ProjectName ");
da = new SqlDataAdapter(str.ToString(), con);
da.Fill(dtProjects);
}
tvProject.Nodes.Clear();
TreeNode rootNode = new TreeNode("All Projects");
rootNode.Expanded = true;
foreach (DataRow drRelease in dtRelease.Rows)
{
TreeNode releaseNode = new TreeNode((string)drRelease["Name"]);
DataRow[] releaseProjects = dtProjects.Select("(ReleaseId = " + drRelease["ReleaseId"] + ") AND (ParentProjectId IS NULL)");
foreach (DataRow drProject in releaseProjects)
{
TreeNode projectNode = new TreeNode((string)drProject["ProjectName"], drProject["ProjectId"].ToString());
projectNode.ToolTip = "This is a project node and is selectable";
loadTVNode((int)drProject["ProjectId"], projectNode, dtProjects);
if (drRelease["EndDate"] != System.DBNull.Value)
{
string s = ((DateTime)drRelease["EndDate"]).ToString(Global.CONST_DateFormat);
releaseNode.ToolTip = "Release scheduled for deployment on " + s;
}
else
releaseNode.ToolTip = "Release deployment has not been scheduled";
releaseNode.ToolTip += ". This node is not selectable";
releaseNode.ChildNodes.Add(projectNode);
}
rootNode.ChildNodes.Add(releaseNode);
}
tvProject.Nodes.Add(rootNode);
問:我的頁面上的樹視圖會有一個代碼,它會使用這個構造器方法,並使用以下語法:MyTree.BuildTreeView(); ?? – kacalapy 2010-11-11 16:32:54