- 建立在專案中加入UserBean.cs 寫完後記得先對Project compiler
class UserBean
{
private string name;
public string Name
{
get { return name; }
set { name = value; }
}
private int age;
public int Age
{
get { return age; }
set { age = value; }
}
private string sex;
public string Sex
{
get { return sex; }
set { sex = value; }
}
public UserBean()
{
}
public UserBean(string name, int age, string sex)
{
this.name = name;
this.age = age;
this.sex = sex;
}
} - 在WinForm裡放入一ReportViewer
- 在ReportViewer選擇設計新報表
- 資料來原選擇物件
- 勾選UserBean > 完成
- 在WinForm Loading寫入
List<UserBean> userBeanList1 = new List<UserBean>();
List<UserBean> userBeanList1 = new List<UserBean>();
userBeanList1.Add(new UserBean("Bob", 30, "M"));
userBeanList2.Add(new UserBean("Alice", 25 ,"F"));
reportViewer1.LocalReport.DataSources.Clear();
ReportDataSource rd1 = new ReportDataSource("user1", userBeanList1);
ReportDataSource rd2 = new ReportDataSource("user2", userBeanList2);
reportViewer1.LocalReport.DataSources.Add(rd1);
reportViewer1.LocalReport.DataSources.Add(rd2);
this.reportViewer1.RefreshReport(); - 在rdlc中修改(加入)資料集(DataSet)名稱
- 結果
2015年1月15日 星期四
[C#] WinForm Report (.rdlc) with multiple datasources(Bean)
參考資料來源 How to create Microsoft Report (.rdlc) with multiple datasources in ASP.NET.
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言