} dr.Close (); }
private void TreeView1_SelectedIndexChange(object sender, Microsoft.Web.UI.WebControls.TreeViewSelectEventArgs e) { TreeNode NewNode=TreeView1.GetNodeFromIndex (TreeView1.SelectedNodeIndex); string strNodeId=NewNode.ID .ToString (); SqlDataReader dr; SqlCommand myCommand; int intVOrderLen=strNodeId.Length+2; string strSel = "select * from bas_enterprise where len(vieworder)="+intVOrderLen+" and vieworder like '%"+strNodeId+"__%' order by vieworder"; myCommand = new SqlCommand (strSel, myConnection); dr=myCommand.ExecuteReader(); NewNode.Nodes .Clear(); while (dr.Read ()) { TreeNode pNode=new TreeNode (); pNode.Text =dr["EntpName"].ToString (); pNode.ID =dr["ViewOrder"].ToString (); NewNode.Nodes.Add (pNode); } dr.Close (); TreeView1.ExpandLevel=1; }
8、在treeview中如何查找一个值,并选中它? 问题: 各位,在已经建好的树中如何查找一个文本或者是treenodes的id,找到后选中它? 答案: for(int i=0;i<TreeView1.Nodes.Count;i++) if(TreeView1.Nodes[i]==TextBox1.Text) { string index1=TreeView1.Nodes[i].GetNodeIndex();//取得index TreeView1.SelectedNodeIndex=index1; } 9、如何取得TreeView中各项的值?? private void TreeView1_SelectedIndexChange(object sender, Microsoft.Web.UI.WebControls.TreeViewSelectEventArgs e) { Microsoft.Web.UI.WebControls.TreeNode NewNode=TreeView1.GetNodeFromIndex(TreeView1.SelectedNodeIndex); Label1.Text =NewNo
如果通过代码要在父结点中增加子节点,代码如何实现? 父节点代码如下: TreeNode pNode = new TreeNode(); pNode.ID = "Root"; pNode.Text = strNodeName; TreeView1.Nodes.Add(pNode); 如果要在根结点"Root"下面再增加子节点,如何写代码? TreeView1.Nodes.AddAt(pNode);这种方式好象不行. TreeView1.Nodes[0].Nodes.Add(pNewNode);
/*************.Cs 中的代码**************************** string strScript="<script language=\"javascript\" >"; strScript+=" function GetNode() \n"+"{ \n"; strScript+=" alert(TreeView1.getTreeNode(TreeView1.clickedNodeIndex).getAttribute('Text'));\n" ; strScript+=" alert(TreeView1.getTreeNode(TreeView1.clickedNodeIndex).getAttribute('CheckBox'));\n"; strScript+=" alert(TreeView1.getTreeNode(TreeView1.clickedNodeIndex).getAttribute('Checked'));\n"; strScript+=" if (TreeView1.getTreeNode(TreeView1.clickedNodeIndex).getAttribute('Checked'))\n"; strScript+=" TreeView1.getTreeNode(TreeView1.clickedNodeIndex).setAttribute('Checked','false');\n"; strScript+=" else \n"; strScript+=" TreeView1.getTreeNode(TreeView1.clickedNodeIndex).setAttribute('Checked','true');\n"; strScript+=" \n } \n"; strScript+="</script>"; if(! this.IsClientScriptBlockRegistered("myjs")) { this.RegisterClientScriptBlock("myjs",strScript); }
|