2

我目前正在尝试使用 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 的一部分?

4

1 回答 1

5

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

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

    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;
于 2011-06-30T20:20:59.457 回答