我做了两个实体类,我想把mer.GetProducts()中取到的数据放到Report1.rdlc报表中
1.是不是我在xaml文件中要设置一下DataSurce的name啊.我一直找不到解决方法.
2.用实体类的List绑定到数据源的方式我这样做法对吗.
请高手指点.Window1.xaml代码如下
<Window x:Class="WpfApplication2.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:viewer="clr-namespace:Microsoft.Reporting.WinForms;assembly=Microsoft.ReportViewer.WinForms"
Title="Window1" Height="300" Width="300" Loaded="Window_Loaded"> <DockPanel Name="panel1" LastChildFill="True">
<my:WindowsFormsHost Margin="341,249,237,165" Name="windowsFormsHost1"
xmlns:my="clr-namespace:System.Windows.Forms.Integration;assembly=WindowsFormsIntegration" OverridesDefaultStyle="False">
<viewer:ReportViewer Name="rp" Width="1000" Height="10000" > </viewer:ReportViewer>
</my:WindowsFormsHost>
</DockPanel>
</Window>Window1.cs代码如下
private void Window_Loaded(object sender, RoutedEventArgs e)
{
//this.ReportViewer1.ProcessingMode = Microsoft.Reporting.WinForms.ProcessingMode.Local;
//this.ReportViewer1.LocalReport.ReportPath = @"E:\C#\WpfApplication2\WpfApplication2\Report\Report1.rdlc";
//this.ReportViewer1.LocalReport.Refresh(); Microsoft.Reporting.WinForms.ReportViewer rep = new Microsoft.Reporting.WinForms.ReportViewer();
rep.LocalReport.ReportPath = @"E:\C#\WpfApplication2\WpfApplication2\Report\Report1.rdlc";
Merchant mer = new Merchant();
rep.LocalReport.DataSources.Add(new Microsoft.Reporting.WinForms.ReportDataSource([color=#0000FF]"Test" ,mer.GetProducts()));[/color]
rep.RefreshReport(); }实体类
public class Product
{
private string m_name;
private int m_price;
public Product(string name, int price)
{
m_name = name; m_price = price;
} public string Name
{
get
{
return m_name;
} } public int Price
{
get
{
return m_price;
}
}
}
*********************************************
public class Merchant
{
private List<Product> m_products;
public Merchant()
{
m_products = new List<Product>();
m_products.Add(new Product("Pen", 25));
m_products.Add(new Product("Pencil", 30));
m_products.Add(new Product("Notebook", 15));
} public List<Product> GetProducts()
{
return m_products;
}
}
1.是不是我在xaml文件中要设置一下DataSurce的name啊.我一直找不到解决方法.
2.用实体类的List绑定到数据源的方式我这样做法对吗.
请高手指点.Window1.xaml代码如下
<Window x:Class="WpfApplication2.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:viewer="clr-namespace:Microsoft.Reporting.WinForms;assembly=Microsoft.ReportViewer.WinForms"
Title="Window1" Height="300" Width="300" Loaded="Window_Loaded"> <DockPanel Name="panel1" LastChildFill="True">
<my:WindowsFormsHost Margin="341,249,237,165" Name="windowsFormsHost1"
xmlns:my="clr-namespace:System.Windows.Forms.Integration;assembly=WindowsFormsIntegration" OverridesDefaultStyle="False">
<viewer:ReportViewer Name="rp" Width="1000" Height="10000" > </viewer:ReportViewer>
</my:WindowsFormsHost>
</DockPanel>
</Window>Window1.cs代码如下
private void Window_Loaded(object sender, RoutedEventArgs e)
{
//this.ReportViewer1.ProcessingMode = Microsoft.Reporting.WinForms.ProcessingMode.Local;
//this.ReportViewer1.LocalReport.ReportPath = @"E:\C#\WpfApplication2\WpfApplication2\Report\Report1.rdlc";
//this.ReportViewer1.LocalReport.Refresh(); Microsoft.Reporting.WinForms.ReportViewer rep = new Microsoft.Reporting.WinForms.ReportViewer();
rep.LocalReport.ReportPath = @"E:\C#\WpfApplication2\WpfApplication2\Report\Report1.rdlc";
Merchant mer = new Merchant();
rep.LocalReport.DataSources.Add(new Microsoft.Reporting.WinForms.ReportDataSource([color=#0000FF]"Test" ,mer.GetProducts()));[/color]
rep.RefreshReport(); }实体类
public class Product
{
private string m_name;
private int m_price;
public Product(string name, int price)
{
m_name = name; m_price = price;
} public string Name
{
get
{
return m_name;
} } public int Price
{
get
{
return m_price;
}
}
}
*********************************************
public class Merchant
{
private List<Product> m_products;
public Merchant()
{
m_products = new List<Product>();
m_products.Add(new Product("Pen", 25));
m_products.Add(new Product("Pencil", 30));
m_products.Add(new Product("Notebook", 15));
} public List<Product> GetProducts()
{
return m_products;
}
}
解决方案 »
- 一次生成多张缩略图..急急急
- 请问能否在C#中使用C++Builder编译的DLL?
- 怎么我的richTextBox显示中文会出现乱码的?
- C#开发winform用到的datagrid,怎样合并单元格?
- 如何使电脑只上某几个网站
- 关于Listview控件问题
- C#连接Access数据库insert操作时,debug目录下临时数据库修改了,但是原数据库不变。
- .NET 串口号(COM口)操作系统自动分配
- 问几个小问题,请指教!
- 水晶报表的一些问题,谁能帮帮我呀
- VS2008(C#)与SQL2005连接时错误提示是error:40,请问怎么设置SQL的外围应用配置器和SQL的应用管理器?
- 引用dbml文件里的 存储过程 获取数据的问题!!
2.创建报表文件并绑定实体的dataset
3.创建一个页面 放置ReportViewer 然后再该页面下面写绑定代码 很简单
{ DataSet dsGet = CreateTotalDatatable(monthId); this.ReportViewer1.ProcessingMode = ProcessingMode.Local; ReportViewer1.LocalReport.ReportPath = Server.MapPath("..") + @"/ReportFiles/rptModelChannel1.rdlc";
ReportViewer1.LocalReport.DataSources.Clear(); ReportViewer1.LocalReport.DataSources.Add(new ReportDataSource("dsModelChannel_dtModelChannel", dsGet.Tables[0]));
ReportViewer1.LocalReport.DataSources.Add(new ReportDataSource("dsModelChannel_dtWeek", dsGet.Tables[1]));
ReportViewer1.LocalReport.DataSources.Add(new ReportDataSource("dsModelChannel_dtModelChannelNonePerson", dsGet.Tables[2])); ReportParameter rp_CompanyName = new ReportParameter("rp_CompanyName",SessionState.CurrentUser.ShopName);
ReportParameter rp_LastId;
if (dsGet.Tables[0].Rows.Count > 0)
{
rp_LastId = new ReportParameter("rp_LastId", dsGet.Tables[0].Rows[dsGet.Tables[0].Rows.Count - 1]["brand_id"].ToString());
}
else
{
rp_LastId = new ReportParameter("rp_LastId", "-1");
}
ReportViewer1.LocalReport.SetParameters(new ReportParameter[] { rp_CompanyName, rp_LastId }); ReportViewer1.LocalReport.Refresh(); }
ReportParameter rp_CompanyName = new ReportParameter("rp_CompanyName",SessionState.CurrentUser.ShopName);
ReportParameter rp_LastId;
if (dsGet.Tables[0].Rows.Count > 0)
{
rp_LastId = new ReportParameter("rp_LastId", dsGet.Tables[0].Rows[dsGet.Tables[0].Rows.Count - 1]["brand_id"].ToString());
}
else
{
rp_LastId = new ReportParameter("rp_LastId", "-1");
}
ReportViewer1.LocalReport.SetParameters(new ReportParameter[] { rp_CompanyName, rp_LastId });