【问题标题】:ASP.net DataList doesn't show any thingASP.net DataList 不显示任何内容
【发布时间】:2013-03-26 16:58:16
【问题描述】:

我的页面中有 DataList1。我想通过命令填充 Datalist 。但是使用此代码 Datalist 不会显示任何内容。但是当我使用 gridview 时, Gridview 显示 4 行:

        db = new da();
        dt = new DataTable();
        string sql = "SELECT TOP (4) id, titr, sum  FROM newstxt ORDER BY views desc";
        dt = db.select(sql);

        DataList1.DataSource = dt;
        DataList1.DataBind();
        GridView1.DataSource = dt;
        GridView1.DataBind();

da 是一个用于执行 sql 命令的类。

【问题讨论】:

  • 一个基于3层做sqlcommand的类
  • 您是否将列适当地添加到数据列表中,因为 gridview 会自动生成但数据列表不会。
  • Datalist 没有 columns 属性

标签: asp.net visual-studio-2010 datalist


【解决方案1】:

您应该在 datalist 标记中指定项目模板,例如:

<ItemTemplate>
<%#Container.DataItem("id")%>
</ItemTemplate>

查看这篇文章以获取示例:DataList Example in ASP.NET using C#

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-09-29
    • 2020-11-10
    • 2012-04-12
    • 2019-11-11
    • 2017-09-25
    • 2012-08-02
    • 2019-08-11
    • 2018-06-25
    相关资源
    最近更新 更多