Filter Treeview For PDF Documents RRS feed

  • Question

  • User-666661156 posted

    Hey Everyone,

    I am populating a Treeview from a database with PDF documents. In SQL I have two tables, Table 1 contains a section ID and Section Name. Table 2 consists of the section ID and the name of the PDF file that needs to be displayed under each section. My issue is that the PDF file is being populated under the incorrect section even though the stored procedure is returning the result correctly.

    Here's my code:

    Partial Class Controls_Resources
    Inherits System.Web.UI.UserControl
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    If Not Page.IsPostBack Then
    gvResources.DataSource = FranchiseePortal.GetResources(CInt(Session("userid")))
    End If
    End Sub
    Protected Sub gvResources_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles gvResources.PreRender
    Dim tvResources As TreeView
    Dim secID As Integer
    Dim sectionname As String
    Dim ds As DataSet
    Dim row As DataRowView
    Dim filteredView1, filteredView2 As DataView
    Dim x, SectionID As Integer
    Dim NewNode As TreeNode
    Dim NewChildNode As TreeNode
    ds = FranchiseePortal.GetResources(CInt(Session("userid")))
    Dim i As Integer
    For i = 0 To gvResources.Rows.Count - 1
    tvResources = CType(gvResources.Rows(i).FindControl("tvResources"), TreeView)
    store = CInt(gvResources.Rows(i).Cells(0).Text)
    storename = CStr(ds.Tables(0).Rows(i).Item(1))
    tvResources.Nodes(0).Text = sectionname
    tvResources.Nodes(0).SelectAction = TreeNodeSelectAction.Expand
    tvResources.Nodes(0).Expanded = True
    tvResources.Nodes(0).ImageUrl = "../images/dicon_folder_closed.gif"
    filteredView1 = New DataView(ds.Tables(1))
    filteredView1.RowFilter = "SectionID =" & secID
    For Each row In filteredView1 
    SectionID = CInt(row("SectionID"))
    NewNode = New TreeNode(row("ReportName").ToString(), row("SectionID").ToString())
    NewNode.SelectAction = TreeNodeSelectAction.Expand
    NewNode.Expanded = False
    NewNode.ImageUrl = "../images/dicon_folder_closed.gif"
    filteredView2 = New DataView(ds.Tables(1))
    filteredView2.RowFilter = "SectionID =" & secID
    Dim row2 As DataRowView
    For Each row2 In filteredView2
    If x = 0 Then
    If Not IsDBNull(filteredView2.Item(x).Item("ReportName")) Then
    NewChildNode = New TreeNode(filteredView2.Item(x).Item("ReportName").ToString())
    NewChildNode.NavigateUrl = "../PDFviewer.aspx?secID=" & secID NewChildNode.Target = "_blank"
    NewChildNode.ImageUrl = "../Images/dicon_pdf.gif"
    End If
    End If
    NewNode.PopulateOnDemand = False
    End Sub
    End Class

    Control Code:

    <%@ Control Language="VB" AutoEventWireup="false" CodeFile="Resources.ascx.vb" Inherits="Controls_Resources" %>
    <asp:GridView runat="server" ID="gvResources" AutoGenerateColumns="False" Width="100%" BorderWidth="1" CssClass="promoBox" BorderColor="black">
    <HeaderStyle BackColor="Black" ForeColor="White" HorizontalAlign="Center" Font-Size="Smaller"/>
    <asp:BoundField DataField="SectionID" HeaderText="Resource #">
    <HeaderStyle Width="20%" />
    <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" Wrap="False" />
    <asp:TemplateField HeaderText="Section Name">
    <asp:TreeView runat="server" ID="tvResources" MaxDataBindDepth="5">
    <asp:TreeNode Text="Name" Value="SectionName"></asp:TreeNode>
    <HeaderStyle HorizontalAlign="Center" Width="60%" />
    <ItemStyle HorizontalAlign="Left" VerticalAlign="Middle" />

    This is the outcome:

    The PDF should be under Section 1 and not Section 4. Any ideas?


    Tuesday, November 19, 2013 4:39 PM

All replies

  • User488649576 posted


    According to your description and the code you provided, I think you should debug the function gvResources_PreRender(), to debug it steps by steps, to find in which rows, it will display the document.

    Maybe we should update the logic of the code.

    Wednesday, November 20, 2013 3:29 AM
  • User-666661156 posted

    I tried changing the value of X to 1 or 2 but it didn't change anything. Although while stepping through the code on this line

    NewChildNode = New TreeNode(filteredView2.Item(x).Item("ReportName").ToString())

    The PDF filename is being recognized under the correct section so I'm not sure as to what's happening. When I add additional filenames into different sections they get put into the appropriate section only though they first start at Section 4 for some reason and the move their way upwards to the other sections.

    Wednesday, November 20, 2013 10:23 AM