描述:对Report server做了一个小练习,算是入门,但发现运行起来后,页面一直处于加载状态,不知为何?

解决:查了一下网上的资料,解决的方法是

  protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
Show();
}
}
public void Show()
{
try
{
string conn = System.Configuration.ConfigurationManager.ConnectionStrings["WX_TESTConnectionString"].ConnectionString;
SqlConnection Sqlcon = new SqlConnection(conn);
SqlCommand Sqlcmd = new SqlCommand("select * from Person", Sqlcon);
SqlDataAdapter SqlDA = new SqlDataAdapter();
DataSet ds = new DataSet();
SqlDA.SelectCommand = Sqlcmd;
SqlDA.Fill(ds);
Sqlcon.Close(); //重新绑定报表数据源
this.ReportViewer1.LocalReport.ReportPath = AppDomain.CurrentDomain.BaseDirectory + "Report1.rdlc";
this.ReportViewer1.LocalReport.DataSources.Clear();
this.ReportViewer1.LocalReport.DataSources.Add(new Microsoft.Reporting.WebForms.ReportDataSource("DataSet1", ds.Tables[]));
this.ReportViewer1.LocalReport.Refresh();
}
catch (Exception ex)
{
throw ex;
}
}

关键就在于show()这个方法不能直接写在Page_Load,要判断回传页面(IsPostBack)在执行show()!

  

05-18 21:56