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

有帮助吗?

解决方案

I know it is a bit late, but stil if you haven't found the answer yet, I'll post this jost in case.

I had the same problem which I solved by binding elements to data first and only then did the datarepeater binding. So your code should look like this:

    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;
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top