2014-12-30 2 views
-1

트리뷰로 변경해야하는 체크 박스 목록이 있습니다. 나는 그것을했지만 지금 내가 원하는 것은 체크 박스 목록에서 이루어진 것처럼 트리 뷰 (onclick)에서 체크 된 항목을 검색하는 것이다. 체크 박스 목록에서 cblist.Items [k] .Selected를 사용하여 항목을 가져올 수 있습니다.
TreeView로 어떻게 할 수 있습니까?체크 박스 목록에서 트 리뷰보기

또 다른 질문은 어떻게 계산합니까?

private void Tree() 
{ 
    try 
    { 
     Dados d = new Dados(); 
     DataTable dtTree = d.getTreeView("%"); 

     DataSet ds = new DataSet("table"); 
     ds.Tables.Add(dtTree); 

     ds.Relations.Add("ChildRows", ds.Tables[0].Columns["ID"], 
       ds.Tables[0].Columns["ParentID"]); 

     foreach (DataRow level1DataRow in ds.Tables[0].Rows) 
     { 
      if (string.IsNullOrEmpty(level1DataRow["ParentID"].ToString())) 
      { 
       TreeNode parentTreeNode = new TreeNode(); 
       parentTreeNode.Text = "<span style=\"color:" + level1DataRow["Color"].ToString() + "\">" + level1DataRow["Description"].ToString() + "</span>"; 
       GetChildRows(level1DataRow, parentTreeNode); 
       Treeview1.Nodes.Add(parentTreeNode); 

      } 
     } 
    } 
    catch (Exception ex) 
    { 
     //something 
    } 
} 

private void GetChildRows(DataRow dataRow, TreeNode treeNode) 
{ 
    DataRow[] childRows = dataRow.GetChildRows("ChildRows"); 
    foreach (DataRow row in childRows) 
    { 
     TreeNode childTreeNode = new TreeNode(); 
     childTreeNode.Text = "<span style=\"color:" + row["Color"].ToString() +"\">" + row["Description"].ToString() +"</span>"; 
     childTreeNode.Value = row["LocalID"].ToString(); 
     treeNode.ChildNodes.Add(childTreeNode); 


     if (row.GetChildRows("ChildRows").Length > 0) 
     { 
      GetChildRows(row, childTreeNode); 
     } 
    } 
} 

그리고 checkboxlist

private void cbox() 
{ 
    try 
    { 
     Dados d = new Dados(); 
     string instalacao = ""; 
     DataTable dtList = d.getLocal("%"); 

     DataView dataView = new DataView(dtList); 
     dataView.Sort = " Color asc, Description asc"; 

     cblist.DataSource = dataView; 
     cblist.DataTextField = "Description"; 
     cblist.DataValueField = "LocalID"; 
     cblist.DataBind(); 
    } 
    catch (Exception ex) 
    { 
     //something 
    } 
} 
+1

는 일부 코드 메이트를 표시합니다. –

답변

0

사용 TreeView.SelectedNode

<%@ Page Language="C#" %> 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<script runat="server"> 

    void Select_Change(Object sender, EventArgs e) 
    { 

     Message.Text = "You selected: " + LinksTreeView.SelectedNode.Text; 

    } 

</script> 

<html xmlns="http://www.w3.org/1999/xhtml" > 

    <head runat="server"> 
    <title>TreeView SelectedNodeStyle Example</title> 
</head> 
<body> 
     <form id="form1" runat="server"> 

      <h3>TreeView SelectedNodeStyle Example</h3> 

      <asp:TreeView id="LinksTreeView" 
       Font-Names= "Arial" 
       ForeColor="Blue" 
       SelectedNodeStyle-ForeColor="Green" 
       SelectedNodeStyle-VerticalPadding="0" 
       OnSelectedNodeChanged="Select_Change" 
       runat="server"> 

       <LevelStyles> 

        <asp:TreeNodeStyle ChildNodesPadding="10" 
         Font-Bold="true" 
         Font-Size="12pt" 
         ForeColor="DarkGreen"/> 
        <asp:TreeNodeStyle ChildNodesPadding="5" 
         Font-Bold="true" 
         Font-Size="10pt"/> 
        <asp:TreeNodeStyle ChildNodesPadding="5" 
         Font-UnderLine="true" 
         Font-Size="10pt"/> 
        <asp:TreeNodeStyle ChildNodesPadding="10" 
         Font-Size="8pt"/> 

       </LevelStyles> 

       <Nodes> 

        <asp:TreeNode Text="Table of Contents" 
         SelectAction="None"> 

         <asp:TreeNode Text="Chapter One"> 

          <asp:TreeNode Text="Section 1.0"> 

           <asp:TreeNode Text="Topic 1.0.1"/> 
           <asp:TreeNode Text="Topic 1.0.2"/> 
           <asp:TreeNode Text="Topic 1.0.3"/> 

          </asp:TreeNode> 

          <asp:TreeNode Text="Section 1.1"> 

           <asp:TreeNode Text="Topic 1.1.1"/> 
           <asp:TreeNode Text="Topic 1.1.2"/> 
           <asp:TreeNode Text="Topic 1.1.3"/> 
           <asp:TreeNode Text="Topic 1.1.4"/> 

          </asp:TreeNode> 

         </asp:TreeNode> 

         <asp:TreeNode Text="Chapter Two"> 

          <asp:TreeNode Text="Section 2.0"> 

           <asp:TreeNode Text="Topic 2.0.1"/> 
           <asp:TreeNode Text="Topic 2.0.2"/> 

          </asp:TreeNode> 

         </asp:TreeNode> 

        </asp:TreeNode> 
        <asp:TreeNode Text="Appendix A" /> 
        <asp:TreeNode Text="Appendix B" /> 
        <asp:TreeNode Text="Appendix C" /> 

       </Nodes> 

      </asp:TreeView> 

      <br /><br /> 

      <asp:Label id="Message" runat="server"/> 

     </form> 
    </body> 
</html> 
관련 문제