Contruction Nodes

8 posts, 0 answers
  1. Caio
    Caio avatar
    11 posts
    Member since:
    Jul 2013

    Posted 16 Jul 2013 Link to this post

    Hi! I have an page with Telerik that uses TreeView concept.
    I use GroupByExpression to construct nodes. But I need construct in my C# an logic that transform an row in SQL with Folders Path in an line in my GridView.
    Ex:
    In my SQL I have an column FolderPath and value is "N:\Test\Drive\FolderTest".
    I need transform this in nodes, or grouping this to ex:

    - N:\
      - Test\
        - Drive\
          -FolderTest\

    How I make it (Nodes or Grouping) in C#?

    Below is my aspx actual.
    <form id="form1" runat="server">
    <Telerik:RadScriptManager runat="server" ID="RadScriptManager1" />
    <Telerik:RadSkinManager ID="QsfSkinManager" runat="server" ShowChooser="false" />
    <Telerik:RadFormDecorator ID="QsfFromDecorator" runat="server" DecoratedControls="All"
        EnableRoundedCorners="false" />
    <Telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
        <AjaxSettings>
            <Telerik:AjaxSetting AjaxControlID="RadGrid1">
                <UpdatedControls>
                    <Telerik:AjaxUpdatedControl ControlID="RadGrid1" LoadingPanelID="RadAjaxLoadingPanel1">
                    </Telerik:AjaxUpdatedControl>
                </UpdatedControls>
            </Telerik:AjaxSetting>
        </AjaxSettings>
    </Telerik:RadAjaxManager>
    <Telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server">
    </Telerik:RadAjaxLoadingPanel>
    <div align="center" style="width: auto; height: auto;">
        <img src="image/NdriveBanner.png" align="center" />
    </div>
    <br />
    <br />
    <Telerik:RadGrid ID="RadGrid1" DataSourceID="SqlDataSource1" runat="server" AllowSorting="True"
        AllowPaging="True" AutoGenerateColumns="False" GridLines="None">
        <PagerStyle Mode="NumericPages"></PagerStyle>
        <MasterTableView Width="100%" GroupLoadMode="Client" TableLayout="Fixed" GroupsDefaultExpanded="false">
            <PagerStyle Visible="false" />
            <GroupByExpressions>
                <Telerik:GridGroupByExpression>
                    <SelectFields>
                        <Telerik:GridGroupByField FieldAlias="REGION" FieldName="REGION"></Telerik:GridGroupByField>
                    </SelectFields>
                    <GroupByFields>
                        <Telerik:GridGroupByField FieldName="REGION"></Telerik:GridGroupByField>
                    </GroupByFields>
                </Telerik:GridGroupByExpression>
                <Telerik:GridGroupByExpression>
                    <SelectFields>
                        <Telerik:GridGroupByField FieldAlias="MARKET" FieldName="MARKET"></Telerik:GridGroupByField>
                    </SelectFields>
                    <GroupByFields>
                        <Telerik:GridGroupByField FieldName="MARKET"></Telerik:GridGroupByField>
                    </GroupByFields>
                </Telerik:GridGroupByExpression>
                <Telerik:GridGroupByExpression>
                    <SelectFields>
                        <Telerik:GridGroupByField FieldAlias="LOCATIONNAME" FieldName="LOCATIONNAME"></Telerik:GridGroupByField>
                    </SelectFields>
                    <GroupByFields>
                        <Telerik:GridGroupByField FieldAlias="LOCATIONNAME" FieldName="LOCATIONNAME"></Telerik:GridGroupByField>
                    </GroupByFields>
                </Telerik:GridGroupByExpression>
            </GroupByExpressions>
            <Columns>
                <Telerik:GridBoundColumn SortExpression="REGION" HeaderText="REGION" HeaderButtonType="TextButton"
                    DataField="REGION">
                </Telerik:GridBoundColumn>
                <Telerik:GridBoundColumn SortExpression="MARKET" HeaderText="MARKET" HeaderButtonType="TextButton"
                    DataField="MARKET">
                </Telerik:GridBoundColumn>
                <Telerik:GridHyperLinkColumn DataNavigateUrlFields="IDSERVER" DataNavigateUrlFormatString="PathFolders.aspx?idServer={0}"
                    DataTextField="LOCATIONNAME" FilterControlAltText="Filter column column" HeaderText="LOCATION NAME"
                    UniqueName="column">
                    <ItemStyle HorizontalAlign="Left" />
                </Telerik:GridHyperLinkColumn>
                <Telerik:GridBoundColumn SortExpression="SERVERNAME" HeaderText="SERVER NAME" HeaderButtonType="TextButton"
                    DataField="SERVERNAME">
                </Telerik:GridBoundColumn>
            </Columns>
        </MasterTableView>
        <ClientSettings ReorderColumnsOnClient="True" AllowDragToGroup="True" AllowColumnsReorder="True">
            <ClientEvents OnGridCreated="demo.GridCreated" />
        </ClientSettings>
        <GroupingSettings ShowUnGroupButton="true"></GroupingSettings>
    </Telerik:RadGrid>
    <br />
    <asp:SqlDataSource ID="SqlDataSource1" ConnectionString="<%$ ConnectionStrings:dbNDriveSecurityConnectionString %>"
        ProviderName="System.Data.SqlClient" SelectCommand="SELECT IDLOCATION,REGION,MARKET,LOCATIONNAME,SERVERNAME,IDSERVER FROM LOCATIONS L INNER JOIN [SERVERS] S ON l.LocationCode = s.LocationCode ORDER BY Region,Market,LocationName,ServerName"
        runat="server"></asp:SqlDataSource>
    </form>
  2. Boyan Dimitrov
    Admin
    Boyan Dimitrov avatar
    1746 posts

    Posted 19 Jul 2013 Link to this post

    Hello,

    An easy and convenient way of achieving such functionality would be to parse the response of your SQL query by the character "/" and add each next string element in that collection as a child of the previous one.


    Regards,
    Boyan Dimitrov
    Telerik
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Caio
    Caio avatar
    11 posts
    Member since:
    Jul 2013

    Posted 19 Jul 2013 Link to this post

    Tks for your answer. But, I'm begginer. What I can make this in my cs? I have an column "sub_folderpath" that have full path for each folder. How I transform this full path in nodes/subnodes for each "/" character, and inform to aspx that it's to grouping? I'm clear? In time, I need an answers for emails that I sent to sales area! You can help my? Tks for all!
  5. Boyan Dimitrov
    Admin
    Boyan Dimitrov avatar
    1746 posts

    Posted 24 Jul 2013 Link to this post

    Hello,

    Please find attached a sample project implementing a very similar scenario - a folder path is parsed and visualized  as tree-view structure using our RadTreeView control.
    //markup code
    <telerik:RadTreeView ID="RadTreeView1" runat="server">
     
    </telerik:RadTreeView>
    //code behind
    protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                string folderPath = "N:\\Test\\Drive\\FolderTest";
                ParseFolderPath(folderPath);
            }
        }
     
        private void ParseFolderPath(string path)
        {
            string[] separateNodes = path.Split('\\');
     
            for (int i = 0; i < separateNodes.Length; i++)
            {
                
                if (i == 0)
                {
                    RadTreeNode currentNode = new RadTreeNode(separateNodes[i]);
                    RadTreeView1.Nodes.Add(currentNode);
                }
                else
                {
                    RadTreeNode childNode = RadTreeView1.Nodes[0];
                     
                    for (int j = 0; j < i; j++)
                    {
                        if (childNode.Nodes.Count <= 0)
                        {
                            childNode.Nodes.Add(new RadTreeNode());
                        }
                        childNode = childNode.Nodes[0];
                         
                        if (j == i - 1)
                        {
                            childNode.Text = separateNodes[i];
                        }
                    }
                }
            }
        }


    Regards,
    Boyan Dimitrov
    Telerik
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
  6. Caio
    Caio avatar
    11 posts
    Member since:
    Jul 2013

    Posted 24 Jul 2013 Link to this post

    I can transform this RadTreeView in an RadGridView? And, I set this string in a foreach, but work just for the first row. I'm trying adapting it. Tks! Attached, I have my actual RadGridView and my TreeView with your code. I need an "treeview" mode to Sub Folder Path but with my GridView template.
  7. Boyan Dimitrov
    Admin
    Boyan Dimitrov avatar
    1746 posts

    Posted 29 Jul 2013 Link to this post

    Hello,

    I would like to clarify that our RadGrid Hierarchy with Templates demo implements very similar scenario. In your case you can use a RadTreeView control inside the NestedViewTemplate instead of RadTabStrip with RadMultiPage with nested RadGrid control as shown in the example. That way you can bind the RadTreeView control to the GridColumn and use the provided logic for iterating and adding nodes based on the folder path from my last response.  

    Regards,
    Boyan Dimitrov
    Telerik
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
  8. Caio
    Caio avatar
    11 posts
    Member since:
    Jul 2013

    Posted 22 Aug 2013 Link to this post

    Hello!!
    I have a list with my all folders. My list have 35 rows.
    But, when I do nodes, it's made in just one folder.

    For example:

    "N:\ALPINO_00" is my first row in my list (listLocations[0]) but in my page, just my row 35 (listLocations[34]) have nodes.
    for all others rows, show just "N".
    "N:\Mathias\level2\level3"

    -N
    --Mathias
    ------------Level2
    ---------------------Level3
    I'm clear? Well, when I make my "ParseFolderPath"  build nodes for all rows?



    protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                var listLocations = new List<string>();
                using (objConexao = new SqlConnection(strStringConexao))
                {
                    using (objCommand = new SqlCommand(strListProfile, objConexao))
                    {
                        try
                        {
                            objConexao.Open();
                            var objDataReader = objCommand.ExecuteReader();
     
                            if (objDataReader.HasRows)
                            {
                                while (objDataReader.Read())
                                {
                                    listLocations.Add(objDataReader.GetString(0));
                                }
                            }
                        }
                        finally
                        {
                            objConexao.Close();
                        }
                    }
                }
                listLocations.ToList();
                ParseFolderPath(listLocations);
            }
        }
     
        private void ParseFolderPath(List<string> paths)
        {
            paths.ForEach(path =>
                {
                    string[] separateNodes = path.Split('\\');
                    for (int i = 0; i < separateNodes.Length; i++)
                    {
     
                        if (i == 0)
                        {
                            RadTreeNode currentNode = new RadTreeNode(separateNodes[i]);
                            RadTreeView1.Nodes.Add(currentNode);
                        }
                        else
                        {
                            RadTreeNode childNode = RadTreeView1.Nodes[0];
     
                            for (int j = 0; j < i; j++)
                            {
                                if (childNode.Nodes.Count <= 0)
                                {
                                    childNode.Nodes.Add(new RadTreeNode());
                                }
                                childNode = childNode.Nodes[0];
     
                                if (j == i - 1)
                                {
                                    childNode.Text = separateNodes[i];
                                }
                            }
                        }
                    }
                });
        }
  9. Boyan Dimitrov
    Admin
    Boyan Dimitrov avatar
    1746 posts

    Posted 27 Aug 2013 Link to this post

    Hello,

    Please find attached a sample of very similar scenario implementation - the RadTreeView control is placed within a MasterViewTable NestedViewTemplate and it could be accessed in order to pass the path string and executed the parsing functionality.

    Please expand a random row and then start interacting with the RadTreeView showing hierarchy structure of the passed path argument. 

    Regards,
    Boyan Dimitrov
    Telerik
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017