【问题标题】:Get Name of directory within DirectoryInfo in DataBinding in c#在c#中的DataBinding中获取DirectoryInfo中的目录名称
【发布时间】:2017-10-16 07:44:14
【问题描述】:

我需要使用 DataBinding

在 c# 中的 asp BoundField 中获取 子文件夹Name

为了知道子文件夹名称,我使用了DirectoryInfo

在编码中我有这个错误:

在所选内容中找不到名为“名称”的字段或属性 数据来源

下面是我的代码。

你能帮帮我吗?

提前感谢您的帮助,非常感谢。

.cs

using (DataSet ds =
    new DataSet())
{
    DataTable dt =
        new DataTable();

    sda.Fill(ds);
    sda.Fill(dt);

    dt = ds.Tables[0];
    string FilePath = HttpContext.Current.Server.MapPath("/myfolder/" + ds.Tables[0].Rows[0]["sFolder"].ToString().Replace('/', '\\'));
    HttpContext.Current.Response.Write(FilePath + "<br /><br />");

    DirectoryInfo directory = new DirectoryInfo(@FilePath);
    DirectoryInfo[] subDirectories = directory.GetDirectories();

    foreach (DirectoryInfo dirInfo in subDirectories)
        HttpContext.Current.Response.Write(dirInfo.Name + "<br />");                                              

    return dt;
}

.aspx

                <asp:GridView ID="gvCustomers" runat="server" AutoGenerateColumns="false" 
                    CssClass="mGrid" Width="500" HorizontalAlign="Center"
                    DataKeyNames="ID" OnRowDataBound="OnRowDataBound">
                    <Columns>
                        <asp:BoundField DataField="Name" HeaderText="Folder name" />
                    </Columns>
                </asp:GridView>

【问题讨论】:

    标签: c# asp.net data-binding directoryinfo


    【解决方案1】:

    请试试这个tutorial

    使用 ASP.Net C# 将多个数据表合并为单个数据表

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-01-16
      • 1970-01-01
      • 1970-01-01
      • 2017-08-14
      • 1970-01-01
      • 2011-06-04
      • 2011-08-26
      • 2017-02-07
      相关资源
      最近更新 更多