我必须使用Crystal Report显示报告。数据集具有值,但crystalReport不显示数据集值。在同一页面上,我也将数据集与gridview绑定在一起。在gridview上,它显示数据,但不在CrystalReportViewer上。 在Google上搜索了此内容,但无法获得任何帮助。
任何对此的建议将不胜感激。
下面是我的代码:
HTML部分:
<CR:CrystalReportViewer ID="CrystalReportViewer2" runat="server" AutoDataBind="true"></CR:CrystalReportViewer>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:BoundField DataField="emp_name" HeaderText="Name" />
<asp:BoundField DataField="emp_father" HeaderText="father" />
<asp:BoundField DataField="emp_contact" HeaderText="contact" />
<asp:BoundField DataField="emp_gender" HeaderText="gender" />
<asp:BoundField DataField="emp_age" HeaderText="age" />
</Columns>
</asp:GridView>
cs代码:
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
GenerateReport();
}
//SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["Myconstr"].ToString());
}
protected void GenerateReport()
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["Myconstr"].ToString());
SqlCommand cmd = new SqlCommand("select * from emp_details", con);
//cmd.CommandType = CommandType.StoredProcedure;
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = cmd;
DataTable datatable = new DataTable();
da.Fill(datatable); // getting value according to imageID and fill dataset
ReportDocument crystalReport = new ReportDocument(); // creating object of crystal report
crystalReport.Load(Server.MapPath("~/CrystalReport1.rpt")); // path of report
crystalReport.SetDataSource(datatable); // binding datatable
CrystalReportViewer2.ReportSource = crystalReport;
GridView1.DataSource = datatable.DefaultView;
GridView1.DataBind();
con.Close();
}