两个字段值在运行时绑定到一个 xrlabel
Two fields values bind to one xrlabel at runtime
我的报告与 DataTable
绑定。我想在我的标签中显示两个字段值。
private void Form1_Load(object sender, EventArgs e)
{
using (rptCustomer rpt = new rptCustomer())
{
rpt.DataSource = CreateTestData();
rpt.DataMember = CreateTestData().TableName;
rpt.xrLabel.Text = "[CustomerID] - [CustomerName]"; // it's doesn't work
//rpt.xrLabel.DataBindings.Add("Text", null, "Customer.CustomerID"); -- it's work
rpt.xrCustomerID.DataBindings.Add("Text", null, "Customer.CustomerID");
rpt.xrCustomerName.DataBindings.Add("Text", null, "Customer.CustomerName");
rpt.xrCustomerAddress.DataBindings.Add("Text", null, "Customer.Address");
rpt.ShowPreviewDialog();
}
}
public DataTable CreateTestData()
{
DataTable dt = new DataTable("Customer");
dt.Columns.Add("CustomerID");
dt.Columns.Add("CustomerName");
dt.Columns.Add("Address");
for (int i = 1; i <= 10; i++)
{
DataRow row = dt.NewRow();
row[0] = i;
row[1] = "Customer " + i;
row[2] = "Address " + i;
dt.Rows.Add(row);
}
return dt;
}
这是我的成绩单。
[CustomerID] - [CustomerName]
必须是 1 - Customer 1
.
您需要使用 DataSet
对象作为报告的数据源。
这是示例:
using (rptCustomer rpt = new rptCustomer())
{
var dataSet = new DataSet("TestDataSet");
var table = CreateTestData();
dataSet.Tables.Add(table);
rpt.DataSource = dataSet;
rpt.DataMember = table.TableName;
rpt.xrLabel.Text = "[CustomerID] - [CustomerName]"; // Suddenly, it's work.
//rpt.xrLabel.DataBindings.Add("Text", null, "Customer.CustomerID"); -- It's work too.
rpt.xrCustomerID.DataBindings.Add("Text", null, "Customer.CustomerID");
rpt.xrCustomerName.DataBindings.Add("Text", null, "Customer.CustomerName");
rpt.xrCustomerAddress.DataBindings.Add("Text", null, "Customer.Address");
rpt.ShowPreviewDialog();
}
我的报告与 DataTable
绑定。我想在我的标签中显示两个字段值。
private void Form1_Load(object sender, EventArgs e)
{
using (rptCustomer rpt = new rptCustomer())
{
rpt.DataSource = CreateTestData();
rpt.DataMember = CreateTestData().TableName;
rpt.xrLabel.Text = "[CustomerID] - [CustomerName]"; // it's doesn't work
//rpt.xrLabel.DataBindings.Add("Text", null, "Customer.CustomerID"); -- it's work
rpt.xrCustomerID.DataBindings.Add("Text", null, "Customer.CustomerID");
rpt.xrCustomerName.DataBindings.Add("Text", null, "Customer.CustomerName");
rpt.xrCustomerAddress.DataBindings.Add("Text", null, "Customer.Address");
rpt.ShowPreviewDialog();
}
}
public DataTable CreateTestData()
{
DataTable dt = new DataTable("Customer");
dt.Columns.Add("CustomerID");
dt.Columns.Add("CustomerName");
dt.Columns.Add("Address");
for (int i = 1; i <= 10; i++)
{
DataRow row = dt.NewRow();
row[0] = i;
row[1] = "Customer " + i;
row[2] = "Address " + i;
dt.Rows.Add(row);
}
return dt;
}
这是我的成绩单。
[CustomerID] - [CustomerName]
必须是 1 - Customer 1
.
您需要使用 DataSet
对象作为报告的数据源。
这是示例:
using (rptCustomer rpt = new rptCustomer())
{
var dataSet = new DataSet("TestDataSet");
var table = CreateTestData();
dataSet.Tables.Add(table);
rpt.DataSource = dataSet;
rpt.DataMember = table.TableName;
rpt.xrLabel.Text = "[CustomerID] - [CustomerName]"; // Suddenly, it's work.
//rpt.xrLabel.DataBindings.Add("Text", null, "Customer.CustomerID"); -- It's work too.
rpt.xrCustomerID.DataBindings.Add("Text", null, "Customer.CustomerID");
rpt.xrCustomerName.DataBindings.Add("Text", null, "Customer.CustomerName");
rpt.xrCustomerAddress.DataBindings.Add("Text", null, "Customer.Address");
rpt.ShowPreviewDialog();
}