本示例代码说明了如何把报表绑定到存储在文件 (本例为 Cars.xml) 中的 XML 数据。 要完成此任务,首先要创建一个 DataSet 对象。 然后通过 ReadXml 方法从 XML 文件装载此数据集,并且把报表中两个已有的标签绑定到数据。
C# | 复制代码 |
---|
using System;
using System.Data;
using System.Windows.Forms;
private void button1_Click(object sender, EventArgs e) {
XtraReport1 report = new XtraReport1();
DataSet xmlDataSet = new DataSet();
xmlDataSet.ReadXml(@"..\..\Cars.xml");
report.DataSource = xmlDataSet;
report.lbModel.DataBindings.Add("Text", report.DataSource,
"Cars.Model", "Model: {0}");
report.lbTrademark.DataBindings.Add("Text", report.DataSource,
"Cars.Trademark", "Trademark: {0}");
report.ShowPreview();
}
|
Visual Basic | 复制代码 |
---|
Imports System
Imports System.Data
Imports System.Windows.Forms
Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs) _
Handles button1.Click
Dim report As New XtraReport1()
Dim xmlDataSet As New DataSet()
xmlDataSet.ReadXml("..\..\Cars.xml")
report.DataSource = xmlDataSet
report.lbModel.DataBindings.Add("Text", report.DataSource, _
"Cars.Model", "Model: {0}")
report.lbTrademark.DataBindings.Add("Text", report.DataSource, _
"Cars.Trademark", "Trademark: {0}")
report.ShowPreview()
End Sub
|
参阅