本文整理汇总了C#中System.Web.UI.WebControls.TreeNode类的典型用法代码示例。如果您正苦于以下问题:C# TreeNode类的具体用法?C# TreeNode怎么用?C# TreeNode使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TreeNode类属于System.Web.UI.WebControls命名空间,在下文中一共展示了TreeNode类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: GetTreeNode
/// <summary>
/// Retrieves the differnt facet members to be placed into TreeNode objects for disaply
/// </summary>
/// <param name="name"></param>
/// <param name="f"></param>
/// <returns></returns>
private TreeNode GetTreeNode(string name, IElement f, string path)
{
TreeNode tn = new TreeNode();
IEnumerable<IModelMember> facetMembers = ContactFacetsHelper.FacetFactory.GetFacetMembers(f);
tn.Text = name;
tn.Value = path;
if (facetMembers != null && facetMembers.Any())
{
foreach (IModelMember modelMember in facetMembers)
{
if (modelMember is IModelAttributeMember && !string.Equals(modelMember.Name, "Preferred", StringComparison.OrdinalIgnoreCase))
{
var newItemPath = string.Format("{0}/{1}", path, modelMember.Name);
var newNode = new TreeNode(modelMember.Name, newItemPath);
newNode.Selected = newItemPath.ToLowerInvariant() == this.MappedFields.Value.ToLowerInvariant();
tn.ChildNodes.Add(newNode);
}
else if (modelMember is IModelElementMember)
{
IModelElementMember modelElementMember = modelMember as IModelElementMember;
tn.ChildNodes.Add(GetTreeNode(modelElementMember.Name, modelElementMember.Element, string.Format("{0}/{1}", path, modelElementMember.Name)));
}
else if (modelMember is IModelDictionaryMember || modelMember is IModelCollectionMember)
{
IModelDictionaryMember dictionaryMember = modelMember as IModelDictionaryMember;
Type type = dictionaryMember == null ? Enumerable.Single<Type>((IEnumerable<Type>)(modelMember as IModelCollectionMember).Elements.GetType().GetGenericArguments()) : Enumerable.Single<Type>((IEnumerable<Type>)dictionaryMember.Elements.GetType().GetGenericArguments());
if (!(type == (Type)null))
tn.ChildNodes.Add(GetTreeNode("Entries", ContactFacetsHelper.FacetFactory.CreateElement(type), string.Format("{0}/{1}", path, "Entries")));
}
}
}
return tn;
}
开发者ID:gillissm,项目名称:WFFM.PopulateFieldAction,代码行数:41,代码来源:ContactFacetDialog.xaml.xml.cs
示例2: CreateSprengelAuswertung
private void CreateSprengelAuswertung (XmlDocument AuszaehlungsStand, TreeView AuszaehlungsTreeView)
{
TreeNode StiegenRootNode = new TreeNode ("Abgegebene Stimmen pro Stiege");
AuszaehlungsTreeView.Nodes.Add (StiegenRootNode);
XmlNode SprengelContainer = AuszaehlungsStand.DocumentElement.SelectSingleNode
("child::" + MBRStatics.MBR_SPRENGEL_DATEN);
foreach (XmlNode StiegenNode in SprengelContainer.SelectNodes("child::" + MBRStatics.MBR_SPRENGEL))
{
String Stiege = StiegenNode.Attributes[MBRStatics.MBR_STIEGE].Value.Replace("_", "/");
String Wohnungen = StiegenNode.SelectSingleNode("child::" + MBRStatics.MBR_WOHNUNGEN).InnerText;
String Schluessel = StiegenNode.SelectSingleNode("child::" + MBRStatics.MBR_SCHLUESSEL).InnerText;
XmlNode AbgegebenNode = StiegenNode.LastChild;
XmlNode ImZeitRaumNode = AbgegebenNode.LastChild;
if (ImZeitRaumNode == null)
continue;
XmlNode AlleNode = ImZeitRaumNode.LastChild;
String Abgegeben = AlleNode.InnerText;
TreeNode StiegenTreeNode = new TreeNode (Stiege + " - " + Wohnungen
+ "(" + Schluessel + ") "
+ Abgegeben + " Stimmen bisher abgegeben");
StiegenRootNode.ChildNodes.Add (StiegenTreeNode);
if (ImZeitRaumNode != null)
foreach (XmlNode Maschine in ImZeitRaumNode.ChildNodes)
{
TreeNode MaschinenNode = new TreeNode (Maschine.InnerText + " " + Maschine.Name);
StiegenTreeNode.ChildNodes.Add (MaschinenNode);
}
}
}
开发者ID:heinzsack,项目名称:DEV,代码行数:33,代码来源:Stundenprofil.aspx.cs
示例3: BindTreeView
/// <summary>
/// 绑定部门
/// </summary>
private void BindTreeView()
{
DataSet ds = mDpt.GetList(" ");
DataTable dt = new DataTable();
dt = ds.Tables[0];
DataRow[] drs = dt.Select(" Dpt_ParentId = 0"); //选出所有根节点
this.tvDaiLi.Nodes.Clear();
TreeNode RootNode = new TreeNode();
RootNode.Text = "<a href='SystemConfigMain.aspx?DPTId=0' onclick='aClick(this);' target='center' >组织机构</a>";
RootNode.Value = "0";
this.tvDaiLi.Nodes.Add(RootNode);
foreach (DataRow dr in drs)
{
string DPTId = dr["Dpt_Id"].ToString();
string DPTName = dr["Dpt_Name"].ToString();
string DPTPARENTID = dr["Dpt_ParentId"].ToString();
TreeNode RootNode2 = new TreeNode();
RootNode2.Text = "<a href='SystemConfigMain.aspx?DPTId=" + DPTId + "' onclick='aClick(this);' target='center' >" + DPTName + "</a>";
RootNode2.Value = DPTId;
RootNode.ChildNodes.Add(RootNode2);
string SonParentID = DPTId;
CreateNode(SonParentID, RootNode2, dt);
}
//this.tvDaiLi.CollapseAll();
}
开发者ID:harvey-chennnnn,项目名称:CatchForm,代码行数:29,代码来源:SystemConfig.aspx.cs
示例4: InitTreeNode
private void InitTreeNode(TreeNodeCollection Nds, string UpDir)
{
string AbsPath = this.AppPath + UpDir + "/";
AbsPath = AbsPath.Replace("/", @"\");
AbsPath = AbsPath.Replace(@"\\", @"\");
TreeNode tmpNd;
string search = "UploadFile.aspx?Dir=";
DataTable dt = FileSystemObject.GetDirectoryInfos(AbsPath, FsoMethod.Folder);
foreach (DataRow dr in dt.Rows)
{
tmpNd = new TreeNode();
string objPath=UpDir+"/"+dr["Name"].ToString();
tmpNd.Value = dr["Name"].ToString();
tmpNd.Text = dr["Name"].ToString();
tmpNd.NavigateUrl = search + base.Server.UrlEncode(objPath);
tmpNd.Target = "main_right";
Nds.Add(tmpNd);
string NextDir=UpDir+"/"+tmpNd.Value;
string aPath = this.AppPath + NextDir + "/";
aPath = aPath.Replace("/", @"\");
aPath = aPath.Replace(@"\\", @"\");
if (FileSystemObject.GetDirectoryInfos(aPath, FsoMethod.Folder).Rows.Count > 0)
{
InitTreeNode(tmpNd.ChildNodes, NextDir);
}
}
}
开发者ID:caisimongit,项目名称:cms-1,代码行数:27,代码来源:UploadDir.aspx.cs
示例5: ShowSelectionTree
private void ShowSelectionTree ()
{
TreeView SelectionTreeView = new TreeView ();
SelectionTreeView.CssClass = "CSS_SelectionTreeView";
this.ContentPlaceHolderNavigationPlace.Controls.Add (SelectionTreeView);
LoadPossibleValues ();
TreeNode StartNode = new TreeNode ("Kalender Durchsuchen nach..");
StartNode.SelectAction = TreeNodeSelectAction.Expand;
SelectionTreeView.Nodes.Add (StartNode);
foreach (DataTable Table in PossibleValues.Tables)
{
String TableName = Table.TableName;
String ColumnName = Table.Columns [0].ColumnName;
TreeNode TableNode = new TreeNode (ColumnName);
TableNode.SelectAction = TreeNodeSelectAction.Expand;
StartNode.ChildNodes.Add (TableNode);
foreach (DataRow TableRow in Table.Rows)
{
String Entry = TableRow [0].ToString ();
TreeNode ContentNode = new TreeNode (Entry);
TableNode.ChildNodes.Add (ContentNode);
ContentNode.NavigateUrl = "./WPMediaCalendarDisplay.aspx?Search=Future&Table=Kalender"
+ "&Column=" + ColumnName + "&Entry=" + Entry;
}
TableNode.Collapse ();
}
}
开发者ID:heinzsack,项目名称:DEV,代码行数:28,代码来源:WPMediaCalendarDisplay.aspx.cs
示例6: btnAddNode_Click
protected void btnAddNode_Click(object sender, EventArgs e)
{
TreeNode myNode = new TreeNode();
myNode.Text = txbText.Text;
myNode.NavigateUrl = txbUrl.Text;
TreeView1.FindNode("Home/Finance/Markets").ChildNodes.Add(myNode);
}
开发者ID:ARHimes78,项目名称:CIS2284,代码行数:7,代码来源:MarketsUS.aspx.cs
示例7: AddTree
//递归添加树的节点
public void AddTree(int ParentID, TreeNode pNode)
{
DataSet ds = (DataSet)this.ViewState["ds"];
DataView dvTree = new DataView(ds.Tables[0]);
//过滤ParentID,得到当前的所有子节点
dvTree.RowFilter = "[c_parent_id] = " + ParentID;
foreach (DataRowView Row in dvTree)
{
TreeNode Node = new TreeNode();
if (pNode == null)
{ //添加根节点
Node.Text = Row["c_province_name"].ToString();
TreeView1.Nodes.Add(Node);
Node.Expanded = true;
AddTree(Int32.Parse(Row["c_id"].ToString()), Node); //再次递归
}
else
{ //̀添加当前节点的子节点
Node.Text = Row["c_province_name"].ToString();
pNode.ChildNodes.Add(Node);
Node.Expanded = true;
AddTree(Int32.Parse(Row["c_id"].ToString()), Node); //再次递归
}
}
}
开发者ID:JayZeeWen,项目名称:Person-Practice,代码行数:27,代码来源:TreeTest.aspx.cs
示例8: LoadFolderNodes
protected void LoadFolderNodes(SPFolder folder, TreeNode folderNode)
{
foreach (SPFolder childFolder in folder.SubFolders)
{
TreeNode childFolderNode = new TreeNode(childFolder.Name, childFolder.Name, FOLDER_IMG);
childFolderNode.NavigateUrl = SPContext.Current.Site.MakeFullUrl(childFolder.Url);
LoadFolderNodes(childFolder, childFolderNode);
folderNode.ChildNodes.Add(childFolderNode);
}
foreach (SPFile file in folder.Files)
{
TreeNode fileNode;
if (file.CustomizedPageStatus == SPCustomizedPageStatus.Uncustomized)
{
fileNode = new TreeNode(file.Name, file.Name, GHOSTED_FILE_IMG);
}
else
{
fileNode = new TreeNode(file.Name, file.Name, UNGHOSTED_FILE_IMG);
}
fileNode.NavigateUrl = SPContext.Current.Site.MakeFullUrl(file.Url);
folderNode.ChildNodes.Add(fileNode);
}
}
开发者ID:Helen1987,项目名称:edu,代码行数:26,代码来源:SiteExplorerUserControl.ascx.cs
示例9: RschPropsListBuilder
public static void RschPropsListBuilder(TreeView tw, int rschId)
{
var tasks = TaskManager.GetTasks(rschId).ToList<Task>();
List<TaskNode> taskNodes = new List<TaskNode>();
foreach (var task in tasks)
{
if (tw.Nodes.Count == 0)
{
tw.Nodes.Add(new TreeNode(TaskManager.GetTaskDescription(task.Type)));
tw.Nodes[0].ChildNodes.Add(new TreeNode(task.Value));
}
else
{
bool placed = false;
foreach (TreeNode n in tw.Nodes)
{
if (n.Text == TaskManager.GetTaskDescription(task.Type))
{
n.ChildNodes.Add(new TreeNode(task.Value));
placed = true;
}
}
if (!placed)
{
TreeNode tnode = new TreeNode(TaskManager.GetTaskDescription(task.Type));
tnode.ChildNodes.Add(new TreeNode(task.Value));
tw.Nodes.Add(tnode);
}
}
//taskNodes.Add(new TaskNode(){Description = TaskManager.GetTaskDescription(task.Type), Value = task.Value});
}
//TaskManager.GetTaskDescription(1);
}
开发者ID:alexkasp,项目名称:monitor,代码行数:33,代码来源:ReportsBuilder.cs
示例10: GenerarMenu
/// <summary>
/// Genera el menu apartir de los resultados de la base de datos
/// </summary>
private void GenerarMenu()
{
List<MENU> menus = null;
List<MENU> menusPadres = null;
List<MENU> submenus = null;
TreeNode item;
TreeNode subitem;
menus = (List<MENU>)Session["Menu"];
menus = menus.OrderBy(menu => menu.NIVELMENU).ToList();
menusPadres = menus.Where(menu => menu.NIVELMENU == 0).ToList();
menusPadres.ForEach(padre =>
{
submenus = menus.Where(x => x.IDMENUPADRE == padre.IDMENU).ToList();
item = new TreeNode
{
Value = padre.DESCRIPCIONMENU,
NavigateUrl = padre.RUTA
};
TreeViewMenu.Nodes.Add(item);
submenus.ForEach(submenu =>
{
subitem = new TreeNode
{
Value = submenu.DESCRIPCIONMENU,
NavigateUrl = submenu.RUTA
};
item.ChildNodes.Add(subitem);
});
});
}
开发者ID:ramirobr,项目名称:DQBase,代码行数:33,代码来源:Site.Master.cs
示例11: PopulateTreeView
int PopulateTreeView(TagElements parentTag, int curentPosition, TreeNode parentNode)
{
// parentTag.hierarchicalPosition = curentPosition;
int j = 0;
foreach (TagElements tag in tagMap)
{
if (tag == null) break;
if (tag.parentName == parentTag.tagName)
{
TreeNode curentNode = new TreeNode();
curentNode.Text = tag.tagName;
curentNode.NavigateUrl = "TagInfo.aspx?tagName=" + tag.tagName;
curentNode.Collapse();
parentNode.ChildNodes.Add(curentNode);
PopulateTreeView(tag, curentPosition + 1, curentNode);
}
j++;
// Response.Write(tag.tagName + " " + tag.parentName + "<br />");
}
return 0;
}
开发者ID:Sergiuu17,项目名称:Timeline,代码行数:26,代码来源:TagsMap.aspx.cs
示例12: show_phongban
private void show_phongban()
{
try
{
execSQL.connectionClass ob = new execSQL.connectionClass();
DataSet ds = ob.fillDataset("EXEC ChungNT.KeHoach_TongHop_DonVi");
DataView dv = ds.Tables[0].DefaultView;
TreeNode child;
foreach (TreeNode node in tvPhongBan.Nodes)
{
dv.RowFilter = string.Format("GroupID = '{0}'", node.Value);
for (int i = 0; i < dv.Count; i++)
{
child = new TreeNode();
child.Value = dv[i][0].ToString();
child.Text = dv[i][1].ToString();
child.ShowCheckBox = true;
child.SelectAction = TreeNodeSelectAction.None;
node.ChildNodes.Add(child);
}
}
lbError.Text = "";
}
catch (Exception ex) { lbError.Text = "Có lỗi trong quá trình đọc dữ liệu. " + ex.Message; }
}
开发者ID:chungnt88,项目名称:DesktopModules,代码行数:25,代码来源:Plan_TongHop.ascx.cs
示例13: PopulateNodes2
private void PopulateNodes2(TreeNodeCollection nodes, int parent)
{
ZhuJi.Portal.IDAL.IPlugin plugin = ZhuJi.AOP.Operator.WrapInterface(typeof(ZhuJi.Portal.NHibernateDAL.Plugin)) as ZhuJi.Portal.IDAL.IPlugin;
IList<ZhuJi.Portal.Domain.Plugin> list = plugin.GetObjects();
ZhuJi.Portal.Domain.PluginCollection plugins = new ZhuJi.Portal.Domain.PluginCollection();
DataTable dt = plugins.CreateDateTable(list);
DataRow[] drs = dt.Select(string.Format("[Parent] = {0}", parent));
if (drs.Length == 0)
{
return;
}
else
{
foreach (DataRow dr in drs)
{
TreeNode tn = new TreeNode();
tn.Text = dr["Title"].ToString();
tn.Value = dr["Id"].ToString();
if (dt.Select(string.Format("[Parent] = {0}", tn.Value)).Length > 0)
{
tn.PopulateOnDemand = true;
}
tn.NavigateUrl = string.Format("AddIn.aspx?PluginId={0}", dr["Id"]);
nodes.Add(tn);
}
}
}
开发者ID:BGCX261,项目名称:zhuji-cms-svn-to-git,代码行数:29,代码来源:Default.aspx.cs
示例14: BindReportTreeData
/// <summary>
/// 绑定报表功能菜单树
/// </summary>
public void BindReportTreeData()
{
tvReport.Nodes.Clear();
DataTable dtReportCategory = WebReportCategoryBLL.Instance.GetAll();
List<TreeNode> nodes = WebReportCategory.WebReportCategoryTree.GetTree(dtReportCategory);
TreeNode root = new TreeNode();
root.Text = "报表功能菜单树";
root.Value = "0";
var listReportInfo = WebReportInfoBLL.Instance.GetAllList("DELETED = 0 and STATUS=1", "CATEGORYID");
int? categoryID = -1;
TreeNode findNode = null;
foreach (var item in listReportInfo)
{
if (categoryID != item.CATEGORYID)
{
findNode = TreeNodeHelper.GetNodeByID(nodes, "" + item.CATEGORYID);
}
if (findNode != null)
{
TreeNode childeNode = new TreeNode();
childeNode.Value = "Info_" + item.ID; //加Info_前缀的目的是防止ID和类别的ID相同
childeNode.Text = "" + item.NAME;
findNode.ChildNodes.Add(childeNode);
categoryID = item.CATEGORYID;
}
}
foreach (TreeNode node in nodes)
{
root.ChildNodes.Add(node);
}
tvReport.Nodes.Add(root);
}
开发者ID:ssjylsg,项目名称:crm,代码行数:38,代码来源:Assign.aspx.cs
示例15: buildBreadcrumbs
protected string buildBreadcrumbs(TreeNode startingNode)
{
if (startingNode == null)
return "<span class=\"breadCrumLabel\">Path</span>";
string internalValuePath = (string)startingNode.GetType().InvokeMember("InternalValuePath", System.Reflection.BindingFlags.Default | System.Reflection.BindingFlags.GetProperty | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance, null, startingNode, null);
string postBackUrl = this.Page.ClientScript.GetPostBackClientHyperlink(this.tv, "s" + internalValuePath, true);
string breadcrumSeparatorImageUrl = this.getImageUrl("breadcrumseparator.gif");
string separator = String.Format("<span class=\"breadCrumSeparator\"> <img src=\"{0}\" alt=\">>\" title=\">>\" /> </span>", breadcrumSeparatorImageUrl);
string nodeText = startingNode.Parent != null ? startingNode.Text : "Storage";
string breadCrum;
if (startingNode == this.tv.SelectedNode)
{
string template = "<span class=\"breadCrumLast\" title=\"{1}\"><img src=\"{0}\" alt=\"{1}\" title=\"{1}\" /> {2}</span> ";
breadCrum = String.Format(template, startingNode.ImageUrl, Utility.QuoteJScriptString(startingNode.ToolTip, false), Utility.QuoteJScriptString(nodeText, false));
}
else
{
string template = "<a href=\"{0}\" title=\"{1}\" class=\"breadCrum\"><img src=\"{2}\" alt=\"{3}\" title=\"{3}\" /> {4}</a> ";
breadCrum = String.Format(template, postBackUrl, Utility.QuoteJScriptString(startingNode.ToolTip, false), startingNode.ImageUrl, Utility.QuoteJScriptString(startingNode.ToolTip, false), Utility.QuoteJScriptString(nodeText, false));
}
string result = this.buildBreadcrumbs(startingNode.Parent) + separator + breadCrum;
if (result.StartsWith(separator))
result = result.Substring(separator.Length);
return result;
}
开发者ID:JamesTryand,项目名称:NetSqlAzMan,代码行数:25,代码来源:WebConsole.aspx.cs
示例16: treeMenu_TreeNodePopulate
protected void treeMenu_TreeNodePopulate(object sender, TreeNodeEventArgs e)
{
string userID = userEntity.UserID;
try
{
DataView dv = new DataView();
string parentId = e.Node.Value.ToString();
dv.Table = ProductTypeDataTable.Copy();
dv.RowFilter = "PSSMEPMC='" + parentId + "' and PSSMEUS='1'";
foreach (DataRowView drv in dv)
{
TreeNode node = new TreeNode();
node.Text = drv["PSSMEMN"].ToString();
node.Value = drv["PSSMEMC"].ToString();
node.PopulateOnDemand = true;
node.SelectAction = TreeNodeSelectAction.Expand;
node.NavigateUrl = drv["PSSMEMP"].ToString();
node.Target = drv["PSSMEOWT"].ToString();
e.Node.ChildNodes.Add(node);
}
}
catch
{
}
}
开发者ID:pcstx,项目名称:OA,代码行数:25,代码来源:leftmenutree.aspx.cs
示例17: AddAt
public void AddAt(int index, TreeNode child)
{
if (child == null)
{
throw new ArgumentNullException("child");
}
if (this._updateParent)
{
if ((child.Owner != null) && (child.Parent == null))
{
child.Owner.Nodes.Remove(child);
}
if (child.Parent != null)
{
child.Parent.ChildNodes.Remove(child);
}
if (this._owner != null)
{
child.SetParent(this._owner);
child.SetOwner(this._owner.Owner);
}
}
this._list.Insert(index, child);
this._version++;
if (this._isTrackingViewState)
{
((IStateManager) child).TrackViewState();
child.SetDirty();
}
this.Log.Add(new LogItem(LogItemType.Insert, index, this._isTrackingViewState));
}
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:31,代码来源:TreeNodeCollection.cs
示例18: BindGrid
/// <summary>
/// 绑定 Treeview Controls
/// </summary>
void BindGrid()
{
this.TVWMenu.Nodes.Clear();
DataSet dsParent = new DataSet();
dsParent.ReadXml(Server.MapPath("~/XMLMenu/RootMenu.xml"));
DataSet dsChild = new DataSet();
dsChild.ReadXml(Server.MapPath("~/XMLMenu/SubMenu.xml"));
DataTable dtbl = dsParent.Tables[0];
foreach (DataRow drow in dtbl.Rows)
{
TreeNode node = new TreeNode();
node.Text = drow["Name"].ToString();
node.Value = drow["ID"].ToString();
AddTree(dsChild, drow["ID"].ToString(), node);
this.TVWMenu.Nodes.Add(node);
}
this.TVWMenu.ExpandAll();
}
开发者ID:JackSunny1980,项目名称:SISKPI,代码行数:28,代码来源:KPI_MgrLeft.aspx.cs
示例19: RenderNode
//����ڵ�����
protected void RenderNode( TreeNode n , HtmlTextWriter writer )
{
writer.WriteLine( "<table border=0 cellspacing=3 cellpadding=0 height='100%' >" );
writer.Write( "<td " );
writer.Write( NodeExtendTag );
writer.Write( ">" );
if (String.IsNullOrEmpty(n.NavigateUrl))
{
writer.Write(n.Text);
}
else
{
writer.Write("<a href='");
writer.Write(n.NavigateUrl);
writer.Write("' target='");
writer.Write(n.Target);
writer.Write("' title='");
writer.Write(n.ToolTip);
writer.Write("' >");
writer.Write(n.Text);
writer.Write("</a>");
}
writer.Write( "</td>" );
writer.WriteLine( "</table>" );
}
开发者ID:porter1130,项目名称:C-A,代码行数:28,代码来源:VerticalRender.cs
示例20: MakeTree
/// <summary>
/// 绑定生成一个有树结构的下拉菜单
/// </summary>
/// <param name="dtNodeSets">菜单记录数据所在的表</param>
/// <param name="strParentColumn">表中用于标记父记录的字段</param>
/// <param name="strRootValue">第一层记录的父记录值(通常设计为0或者-1或者Null)用来表示没有父记录</param>
/// <param name="strIndexColumn">索引字段,也就是放在DropDownList的Value里面的字段</param>
/// <param name="strTextColumn">显示文本字段,也就是放在DropDownList的Text里面的字段</param>
/// <param name="drpBind">需要绑定的DropDownList</param>
/// <param name="i">用来控制缩入量的值,请输入-1</param>
public static void MakeTree(DataTable dtNodeSets, string strParentColumn, string strRootValue, string strIndexColumn, string strTextColumn, DropDownList drpBind, int i)
{
//每向下一层,多一个缩入单位
i++;
DataView dvNodeSets = new DataView(dtNodeSets);
dvNodeSets.RowFilter = strParentColumn + "=" + strRootValue;
string strPading = ""; //缩入字符
//通过i来控制缩入字符的长度,我这里设定的是一个全角的空格
for (int j = 0; j < i; j++)
strPading += " ";//如果要增加缩入的长度,改成两个全角的空格就可以了
foreach (DataRowView drv in dvNodeSets)
{
TreeNode tnNode = new TreeNode();
ListItem li = new ListItem(strPading + "├" + drv[strTextColumn].ToString(), drv[strIndexColumn].ToString());
drpBind.Items.Add(li);
MakeTree(dtNodeSets, strParentColumn, drv[strIndexColumn].ToString(), strIndexColumn, strTextColumn, drpBind, i);
}
//递归结束,要回到上一层,所以缩入量减少一个单位
i--;
}
开发者ID:NickQi,项目名称:TianheDemo,代码行数:35,代码来源:CommTree.cs
注:本文中的System.Web.UI.WebControls.TreeNode类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论