本文介绍了如何绑定在C#中的目录和文件一个ListView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要绑定所有的C盘目录和文件在C#中一个ListView

我的code是:

 保护无效的Page_Load(对象发件人,EventArgs的发送)
{
    DirectoryInfo的DI =新DirectoryInfo的(C:\\\\);    FullDirList(二);
    ListView1.DataSource =善堂;
    ListView1.DataBind();
}ArrayList的LST =新的ArrayList();公共无效FullDirList(DirectoryInfo的DIR1)
{    的foreach(DirectoryInfo的d在dir1.GetDirectories())
    {
        lst.Add(四);
    }    的foreach(FileInfo的f由于dir1.GetFiles())
    {
        lst.Add(F);
    }
}

它提供了以下错误

解决方案

You need to write some aspx like this which includes an ItemTemplate for each list item. That's the error you are getting.

<asp:ListView runat="server" ID="ListView1" 
    DataSourceID="SqlDataSource1">
  <LayoutTemplate>
    <table runat="server" id="table1" >
      <tr runat="server" id="itemPlaceholder" ></tr>
    </table>
  </LayoutTemplate>
  <ItemTemplate>
    <tr runat="server">
      <td runat="server">
        <%-- Data-bound content. --%>
        <asp:Label ID="NameLabel" runat="server" 
          Text='<%#Eval("Name") %>' />
      </td>
    </tr>
  </ItemTemplate>
</asp:ListView>

Example from here

这篇关于如何绑定在C#中的目录和文件一个ListView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 16:07