【问题标题】:How can I bind a DataTable to a DataRepeater(Windows Powerpack) at Runtime?如何在运行时将 DataTable 绑定到 DataRepeater(Windows Powerpack)?
【发布时间】:2011-08-28 03:19:13
【问题描述】:

我目前正在尝试使用 Windows Powerpack DataRepeater 控件来显示来自 DataTable 的数据。

到目前为止,DataRepeater 识别出从数据库调用的结果 DataTable 有 8 行,但我无法获得 3 个文本框(我已放入 DataRepeater 的 ItemTemplate 中)来显示实际所述行中的数据。

DataTable DT = BL.GetDataTable();
BindingSource bSource = new BindingSource();
bSource.DataSource = DT;
DR.DataSource = bSource;

txtEmail.DataBindings.Add("Text", bSource, "Email");
txtID.DataBindings.Add("Text", bSource, "ID");
txtName.DataBindings.Add("Text", bSource, "Name");

因此,一旦查看 DataRepeater(DR),您可以看到 8 行。如果将文本框保留为 DR 的一部分,那么它们会在这 8 行中的每一行上重复,但没有数据。

如果我删除文本框并将它们直接放在表单上,​​然后作为浏览 DR,文本框会显示相应的数据。这不是我要寻找的行为。

有谁知道如何让文本框显示数据并成为 DataRepeater 的一部分?

【问题讨论】:

  • BL.GetDataTable() 中的 BL 是什么; ??
  • BL 可能是指他的“业务逻辑”?

标签: c# datatable datarepeater powerpacks


【解决方案1】:

我知道这有点晚了,但如果你还没有找到答案,我会发布这个问题以防万一。

我遇到了同样的问题,我先将元素绑定到数据,然后才绑定数据中继器。所以你的代码应该是这样的:

    txtEmail.DataBindings.Add("Text", "", "Email");
    txtID.DataBindings.Add("Text", "", "ID");
    txtName.DataBindings.Add("Text", "", "Name");

    DataTable DT = BL.GetDataTable();
    bSource.DataSource = DT;
    DR.DataSource = bSource;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-04-01
    • 2019-06-08
    • 2011-10-12
    • 2014-01-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多