我数据库里有一张表,结构内容如下:
id menuText menuID Rootid Nodeid Role_Live
1 个人信息 1 1 4menuText(目录文本)
menuID(目录级别)
Rootid(一级目录ID)
Nodeid(二级目录ID)
Role_Live(角色)我现在连接数据库没问题,从数据库里取出这个字符串也没问题,
我现在取到数据库内容,把它赋给一个字符串以后我不就知道
怎么来绑定到TreeView上了。
string ss="1 ,个人信息,1,1,, 4";主要是怎么把内容绑定到TreeView上!初学C#请各位师哥帮忙!谢谢!
id menuText menuID Rootid Nodeid Role_Live
1 个人信息 1 1 4menuText(目录文本)
menuID(目录级别)
Rootid(一级目录ID)
Nodeid(二级目录ID)
Role_Live(角色)我现在连接数据库没问题,从数据库里取出这个字符串也没问题,
我现在取到数据库内容,把它赋给一个字符串以后我不就知道
怎么来绑定到TreeView上了。
string ss="1 ,个人信息,1,1,, 4";主要是怎么把内容绑定到TreeView上!初学C#请各位师哥帮忙!谢谢!
解决方案 »
- windows服务 不明原因停止
- winform中日期控件 支持多选
- asp.net MVC如何通过同一个控制器中的两个action读取到同一个View
- WinForm中TextBox控件的Undo和Redo
- C# 用NotifyIcon编写托盘时,出现N多Icon尸体,怎办?
- 紧急求助:怎么连接SQL server
- 要学.net 问个关于dbgrid的问题
- 求救
- 这个C#的dome的源码也看差不多了,基本明白了,但是它只能改变主屏的横纵或者分辨率,隐约觉得肯定哪块的代码小改一下就能达到效果,但是好多地方试了,也不灵,哪位
- 萌新求助
- 在C#.net 中设置数据库变量??请高手多多赐教,小女子先谢过了
- 怎么把textbox搜索到的内容赋給datagrid控件!
void FillTree(TreeNodeCollection Nodes, DataTable nodes, string parentid, int level)
{
for(int i=0;i<nodes.Rows.Count;i++)
{
DataRow node=nodes.Rows[i];
if(node["Testament"].ToString().Trim().Length==0)
continue;//如果没有定义父项,跳过
if((int)node["Level"]!=level)//只有当前级别的项会被处理
continue;
if (node["Testament"].ToString() == parentid)
{
TreeNode treenode=new TreeNode();
treenode.Text =(string)node["ChineseName"];
;
//if(!(node["Url"] is DBNull))
//{
treenode.NavigateUrl = "FrameInfo.aspx?BookID=" + node["BookId"];
treenode.Target = "frameSection";
//if(!(node["ImageUrl"] is DBNull))
// treenode.ImageUrl=(string)node["ImageUrl"];
//}
Nodes.Add(treenode);
if (Convert.ToInt32(node["Chapters"].ToString()) > 0)
{
for(int j=1;j<=Convert.ToInt32(node["Chapters"].ToString());j++)
{
TreeNode tvchild = new TreeNode("第" + j +"章", "O", null);
tvchild.NavigateUrl = "PagingAndSorting/CustomSortingUI.aspx?BookID=" + node["BookId"] + "&&ChapterID=" + j;
//tvchild.NavigateUrl = "Janus/GridEXDemo/ProgrammingSortingCS.aspx?BookID=" + node["BookId"] + "&&ChapterID=" + j;
tvchild.Target = "frameSection";
treenode.ChildNodes.Add(tvchild);
}
}
//continue;//如果该项没有定义NodeId,不再搜索其子项
FillTree(treenode.ChildNodes, nodes, node["Testament"].ToString(), level + 1);
}
} }这是例子,看懂就行
运用此控件,您无需在数据库表中设ID,parentID
只需在表中增加一xmltag(字段名任取)与TreeNode.Tag对应就行了
要么分级绑定,先select出一级节点,绑定,点击展开后绑定二级..