2012-04-19 88 views

回答

8
+0

谢谢Pranay ...这些基本的教程是帮助我完全... – 2012-04-19 07:41:11

+1

@SonamMohite - 你是欢迎..等待upvote对我的答案.. – 2012-04-19 07:43:08

+0

嘿Pranay ....首先感谢帮助我。关于使用存储过程创建数据集并没有什么困惑。因为我已经使用DataSet和Table很好地工作,所以现在想试试这个。你可以为此发布代码。 – 2012-04-21 05:42:33

1

我的代码工作创造报告业务类对象...

创建使用商务舱报表对象&的ReportViewer(ASP.NET/ C#) 1,创建学生班级

public class StudentClass 
    { 
     public int No { get; set; } 
     public string Name { get; set; } 
     public string Degree { get; set; } 
    } 

2.创建学生库与GetStudents()函数

public class StudentRepository : StudentClass 
    { 
     public List<StudentClass> studentList = new List<StudentClass>(); 

     public List<StudentClass> GetStudents() 
     {    
      StudentClass student1 = new StudentClass(); 
      student1.No = 1; 
      student1.Name = "Bhuvana"; 
      student1.Degree = "M.Tech"; 
      studentList.Add(student1); 
      StudentClass student2 = new StudentClass(); 
      student2.No = 2; 
      student2.Name = "Annie"; 
      student2.Degree = "B.Tech"; 
      studentList.Add(student2); 
      StudentClass student3 = new StudentClass(); 
      student3.No = 3; 
      student3.Name = "Muthu Abi"; 
      student3.Degree = "B.Tech"; 
      studentList.Add(student3); 
      return studentList; 
     } 
    } 

3.使用报表向导创建“StudentReport.rdlc”,然后选择数据源

4.In的Index.aspx添加脚本管理和报表查看器从工具箱(拖放)

<div> 
    <asp:ScriptManager ID="ScriptManager1" runat="server"> 
    </asp:ScriptManager> 
    <rsweb:ReportViewer ID="ReportViewer1" runat="server"> 
    </rsweb:ReportViewer>  
</div> 

5.Modify的Page_Load()方法的代码隐藏文件

public partial class Index : System.Web.UI.Page 
{ 
    StudentRepository sr = new StudentRepository(); 
    List<StudentClass> sc = new List<StudentClass>(); 
    protected void Page_Load(object sender, EventArgs e) 
    { 
     if (!IsPostBack) 
     { 
      ReportViewer1.ProcessingMode = ProcessingMode.Local; 
      ReportViewer1.LocalReport.ReportPath = Server.MapPath("~/Report/Student.rdlc"); 
      sc = sr.GetStudents(); 
      IEnumerable<StudentClass> ie; 
      ie = sc.AsQueryable(); 
      ReportDataSource datasource = new ReportDataSource("DataSet1", ie); 
      ReportViewer1.LocalReport.DataSources.Clear(); 
      ReportViewer1.LocalReport.DataSources.Add(datasource); 
     } 

    } 
} 

6.Build而运行

相关问题