问题描述
我正在使用树状视图在基于桌面的项目中进行用户管理
我的树视图名称 mytreeview
myTreeView.CheckBoxes = true; this.Controls.Add(myTreeView); myTreeView.ExpandAll();
现在我想保存和更新复选框在数据库SQLSERVER2005检查的数据.
表名
ParentTable(ParentID,ParentName)
ChildTable(childID的,PARENTID,ChildName,IsActive)
void fill_Tree2(TreeView treeView1) { DataSet PrSet = DB_Manager.SelectDataSet("Select * from service", "sub_header"); treeView1.Nodes.Clear(); try { foreach (DataRow dr in PrSet.Tables["sub_header"].Rows) { TreeNode tnParent = new TreeNode(); tnParent.Text = dr["ParentName"].ToString(); tnParent.Tag = dr["ParentID"].ToString(); tnParent.Expand(); treeView1.Nodes.Add(tnParent); FillChild(tnParent, Convert.ToInt32(tnParent.Tag),treeView1); } }catch(Exception) { } } public void FillChild(TreeNode parent, int ParentId,TreeView treeview1) { DataSet ds = DB_Manager.SelectDataSet("Select * from ServiceSetting where ParentID =" + ParentId + " ", "sub_header"); foreach (DataRow dr in ds.Tables["sub_header"].Rows) { TreeNode child = new TreeNode(); child.Text = dr["ChildName"].ToString().Trim(); child.Tag = dr["ChildId"].ToString().Trim(); parent.Nodes.Add(child); if (Convert.ToInt32(dr["IsActive"]) == 1) { child.Checked = true; } } }
我无法捕获节点ID值.
我在做
后选择检查事件
TreeNode node=new TreeNode(); int NodeID = Convert.ToInt32(node.Tag);
但它can''t工作.
我该如何解决此问题.我想知道树视图复选框如何将选中的数据保存并更新到数据库中.
我是新手开发人员,在此先感谢您.
马苏德
Hi,
I am doing a user Management in Desk top based project using tree view
My tree view Name mytreeview
myTreeView.CheckBoxes = true; this.Controls.Add(myTreeView); myTreeView.ExpandAll();
Now i want to save and Update check box checked data in to database sqlserver2005.
Table Name
ParentTable(ParentID,ParentName)
ChildTable(ChildID,ParentID,ChildName,IsActive)
void fill_Tree2(TreeView treeView1) { DataSet PrSet = DB_Manager.SelectDataSet("Select * from service", "sub_header"); treeView1.Nodes.Clear(); try { foreach (DataRow dr in PrSet.Tables["sub_header"].Rows) { TreeNode tnParent = new TreeNode(); tnParent.Text = dr["ParentName"].ToString(); tnParent.Tag = dr["ParentID"].ToString(); tnParent.Expand(); treeView1.Nodes.Add(tnParent); FillChild(tnParent, Convert.ToInt32(tnParent.Tag),treeView1); } }catch(Exception) { } } public void FillChild(TreeNode parent, int ParentId,TreeView treeview1) { DataSet ds = DB_Manager.SelectDataSet("Select * from ServiceSetting where ParentID =" + ParentId + " ", "sub_header"); foreach (DataRow dr in ds.Tables["sub_header"].Rows) { TreeNode child = new TreeNode(); child.Text = dr["ChildName"].ToString().Trim(); child.Tag = dr["ChildId"].ToString().Trim(); parent.Nodes.Add(child); if (Convert.ToInt32(dr["IsActive"]) == 1) { child.Checked = true; } } }
I can not catch the node id value.
I am doing
After select check event
TreeNode node=new TreeNode(); int NodeID = Convert.ToInt32(node.Tag);
but it can''t work.
How can i solve this problem.I want to know how tree view check box checked data save and update into database.
I am a novice developer,Any Help thanks in advance.
Masud
这篇关于如何保存选中复选框树视图节点的数据到数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!