在page_load()裡面呼叫report()
ui
只拉元件就好了
用SqlDataSource1捉使用者selectquery的dataset 給crystalreport
在到.rpt設定
protected void report()
{
SqlDataSource1.ConnectionString = WebConfigurationManager.ConnectionStrings["TestReportConnectionString"].ConnectionString;
DataTable dt = new DataTable();
String openwin = "";
String sql = TextBox1.Text.Trim();
if (String.IsNullOrEmpty(sql))
{
SqlDataSource1.SelectCommand = "select * from company";
dt = ((DataView)this.SqlDataSource1.Select(DataSourceSelectArguments.Empty)).ToTable();
}
else
{
SqlDataSource1.SelectCommand = "select * from company where companyId=" + "'" + TextBox1.Text + "'";
dt = ((DataView)this.SqlDataSource1.Select(DataSourceSelectArguments.Empty)).ToTable();
}
Response.Cache.SetCacheability(HttpCacheability.NoCache); //clear cache
ReportDocument rd = new ReportDocument();
rd.Load(Server.MapPath("CrystalReport.rpt"));
rd.SetDataSource(dt);
CrystalReportViewer1.ReportSource = rd;
GridView1.DataSourceID = SqlDataSource1.ID;
}
2010年3月14日 星期日
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言