Question

I'm trying to get a list of directories from multiple directories and put them into a gridview. So far so good, I've even included a searchPattern to get the folder names back based on a querystring. However my problem lies when I try and turn the folders path into a hyperlink in the GridView I can't seem to get the column name right and it returns: "DataBinding: 'System.String' does not contain a property with the name 'FullName'." What am I doing wrong? is the Folder path not called "FullName"?

Here's my code, any help appreciated: Code Behind (VB.NET)

 Dim paths As String = "\\xx\PROJECTS\OilGas\;\\xx\PROJECTS\Utils\;\\xx\PROJECTS\Rail\RAIL PROJECTS\PROJECTS - ACTIVE\"
    Dim pathList As String() = paths.Split(";")

    Dim files = New List(Of String)()

    Dim search As String = "*" + qs.Text
    Dim ext As String = "*"

    Dim searchPattern As [String] = [String].Format("{0}*{1}", search, ext)

    For Each str As String In pathList
        Dim d As New DirectoryInfo(str)
        files.AddRange(Directory.GetDirectories(d.FullName, searchPattern))

        GridView1.DataSource = files
        GridView1.DataBind()
    Next    

Griview Code:

<asp:GridView ShowHeader="True" ID="GridView1" runat="server" BorderStyle="None" GridLines="None">
<Columns>
        <asp:TemplateField >
            <ItemTemplate>                   
                <asp:HyperLink ID="HyperLink1" NavigateUrl='' Target="_blank" Text='<%#Eval("FullName")%>' runat="server"></asp:HyperLink>
            </ItemTemplate>
            </asp:TemplateField>
            </Columns>
    <EmptyDataTemplate>
        <em><strong><span style="color: #ff0033">Invalid project code or no project folder found
            with that project code.</span></strong></em>
    </EmptyDataTemplate>
</asp:GridView>

Kind Regards, James.

Was it helpful?

Solution

Your GridView's datasource is a List of string (containing the path of your folders).

Your bound hyperlink contains an Eval instruction asking to retrieve le FullName property of every item of your DataSource. Your DataSource being a List, it could be translated like that :

foreach(string path in files)
{
    HyperLink1.NavigateUrl = path.FullName;
}

Now hopefully you're beginning to see the problem : the string class doesn't have any FullName property.

The solution is to replace the Eval (which is a bad solution anyway, since it does reflection and isn't very efficient) by :

<%# Container.DataItem %>

Which is a typed variable even that you can cast

so you could even write this :

<%# (string)Container.DataItem %>

EDIT : sorry, I wrote code in C#, I hope you'll understand (and that my solution works in VB !)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top