将 DataTable 绑定到 DetailsView 控件

发布于 2024-11-19 16:40:56 字数 280 浏览 2 评论 0原文

我有一个 DetailsView 控件,我想用数据表填充该控件。我在后面的代码中执行此操作。检查数据表创建成功后,代码是:

  detailsView.DataSource = dataTable;
    detailsView.DataBind();

我运行程序,但详细信息视图没有显示。问题是否是数据表可能有多行,而详细信息视图只有一行?如果这就是问题,有办法解决吗?我在创建数据表时确保它只有一行。我还尝试仅绑定数据表中的一行,但不接受数据表行作为数据源。有什么问题吗?

I have a DetailsView control that I want to populate with a data table. I'm doing this in code behind. After checking that the data table is created successfully, the code is:

  detailsView.DataSource = dataTable;
    detailsView.DataBind();

I run the program and the detailsView doesn't show.Could the problem be that a data table potentially can have multiple rows and a details view only one? If that's the problem is there a way of getting around it? I made sure in creating the data table that it has only one row. I also tried binding only one row in the data table but a data table row isn't accepted as a data source. What's the problem?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

你穿错了嫁妆 2024-11-26 16:40:56

您必须添加绑定字段或设置DetailsView AutoGenerateRows="true"才能在详细信息视图中显示该字段。我确信你忘记这样做了..

 <asp:DetailsView ID="DetailsView1" runat="server" Height="50px" Width="125px" >
        <Fields>
            <asp:BoundField DataField="FieldName" HeaderText="Field Title" />
            .......................
            .......................
        </Fields>
    </asp:DetailsView>

You have to add in a Bound field or Set the DetailsView AutoGenerateRows="true" to display the field in the detailsView. I am sure you forget to do this..

 <asp:DetailsView ID="DetailsView1" runat="server" Height="50px" Width="125px" >
        <Fields>
            <asp:BoundField DataField="FieldName" HeaderText="Field Title" />
            .......................
            .......................
        </Fields>
    </asp:DetailsView>
紫轩蝶泪 2024-11-26 16:40:56

DetailView.DataSource = DataSetName;
DetailView.DataMember = DataTableName;

http://www.dotnetspider.com/forum/319762-Datasource -Datamember-In-GridView.aspx

DetailView.DataSource = DataSetName;
DetailView.DataMember = DataTableName;

http://www.dotnetspider.com/forum/319762-Datasource-Datamember-In-GridView.aspx

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文