Show files from 2 different folders in a single Gr

2019-03-04 16:12发布

Is it possible to show files from 2 different folders (c:\test1 and c:\test2) in the same gridview?

I work in VB.net (VS 2010)

Thanks!

3条回答
闹够了就滚
2楼-- · 2019-03-04 16:50

Try something like this:

Dim files As New List(Of String)()
files.AddRange(GetAllFilesFromDir("C:\foo")) 
files.AddRange(GetAllFilesFromDir("C:\bar"))
'GetAllFilesFromDir() must return IEnumerable string
gv.DataSource = files
gv.DataBind()

<asp:gridview ID="gv" runat="server">
    <Columns>
        <asp:TemplateField>
            <ItemTemplate>
                <asp:Label ID="file" runat="server" Text='<%# Container.DataItem %>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
</asp:gridview>

You hadn't shown your code in your question, so the above example demonstrates how this might be done generally.

查看更多
3楼-- · 2019-03-04 17:00

yes. Add them both as collections to List() or any other collection type. Then bind that set to the gridview.

查看更多
我欲成王,谁敢阻挡
4楼-- · 2019-03-04 17:10

Yes. Get list of all the files using Directory.GetFiles() into a single IEnumerable<string> and bind it to a GridView.

This is how you'll do it in c#.

            List<string> allFiles = new List<string>();
            allFiles.AddRange(Directory.GetFiles(@"C:\test1\*"));
            allFiles.AddRange(Directory.GetFiles(@"C:\test2\*"));

            yourGV.DataSource = allFiles;
            yourGV.DataBind();
查看更多
登录 后发表回答