2013-02-22 107 views

回答

0

定義的CustomData CLASSE

public class classData 
{ 
    public String name { get; set; } 

    public classData() 
    { 

    } 
} 

和從VS.添加數據源

preapare列表從數據表

List<classData> lst = new List<classData>(); 

填充列表...

DataRow[] result = datatable.Select(); 
foreach (DataRow row in result) 
{ 
    classDatat = new classData(); 
    t.name = row["name"].ToString(); 
    last.Add(t); 
} 

通數據報告

ReportDataSource rds = new ReportDataSource("DataSet1_Customers_DataTable1", lst); 
reportViewer1.LocalReport.DataSources.Clear(); 
reportViewer1.LocalReport.DataSources.Add(rds); 
reportViewer1.RefreshReport(); 

在報告RDL

<DataSets> 
    <DataSet Name="DataSet1_Customers_DataTable1"> 
     <Fields> 
     <Field Name="NameFromReport"> 
      <DataField>name</DataField> 
      <rd:TypeName>System.String</rd:TypeName> 
     </Field> 
    </DataSet> 
</DataSets> 

,並使用NameFromReport顯示數據

<Textbox Name="textboxName"> 
    <rd:DefaultName>textbox1</rd:DefaultName> 
    <Top>0.25cm</Top> 
    <Width>8.75cm</Width> 
    <Style> 
     <FontFamily>Century Gothic</FontFamily> 
     <FontSize>18pt</FontSize> 
     <FontWeight>700</FontWeight> 
     <PaddingLeft>2pt</PaddingLeft> 
     <PaddingRight>2pt</PaddingRight> 
     <PaddingTop>2pt</PaddingTop> 
     <PaddingBottom>2pt</PaddingBottom> 
    </Style> 
    <ZIndex>1</ZIndex> 
    <CanGrow>true</CanGrow> 
    <Height>1.5cm</Height> 
    <Value>=NameFromReport</Value> 
</Textbox> 

末良好的工作!