1、常用屬性及方法
//常用屬性
CrystalReportViewer1.HasToggleGroupTreeButton = true;//顯示或隱藏工具欄上組樹按鈕
CrystalReportViewer1.HasExportButton = true;//顯示或隱藏工具欄上導出按鈕
CrystalReportViewer1.HasPrintButton = true;//顯示或隱藏工具欄上打印按鈕
CrystalReportViewer1.HasViewList = true;//顯示或隱藏工具欄上視圖列表(主報表)
CrystalReportViewer1.HasDrillUpButton = true;//獲取或設置淺化按鈕可見性(向上)
CrystalReportViewer1.HasPageNavigationButtons = true;//顯示或隱藏工具欄上導航按鈕
CrystalReportViewer1.HasGotoPageButton = true;//顯示或隱藏工具欄上跳轉按鈕
CrystalReportViewer1.HasSearchButton = true;//顯示或隱藏工具欄上搜索按鈕
CrystalReportViewer1.HasZoomFactorList = true;//顯示或隱藏工具欄上縮放按鈕
CrystalReportViewer1.HasCrystalLogo = true;//顯示或隱藏工具欄上LOGO
CrystalReportViewer1.SelectionFormula = "{Customer.Last Year's Sales} > 11000.00 " + "AND Mid({Customer.Customer Name}, 1, 1) = \"A\"";//篩選公式
CrystalReportViewer1.DisplayToolbar = true;//顯示或隱藏工具欄
CrystalReportViewer1.DisplayGroupTree = true;//顯示或隱藏組樹
CrystalReportViewer1.DisplayPage = true;//顯示或隱藏頁面視圖
CrystalReportViewer1.SeparatePages = true;//獲取或設置報表頁是分開還是連接?
CrystalReportViewer1.BorderWidth = Convert.ToInt32("borderWidth");//設置邊框寬度
//常用方法
CrystalReportViewer1.ShowNthPage(Convert.ToInt32("pageNumber"));//跳轉頁
CrystalReportViewer1.Zoom(Convert.ToInt32("zoomFactor"));//縮放
2、登陸驗證
private void ConfigureCrystalReports()
{
ConnectionInfo connectionInfo = new ConnectionInfo();
connectionInfo.ServerName = ".";
connectionInfo.DatabaseName = "Northwind";
connectionInfo.UserID = "sa";
connectionInfo.Password = "";
string reportPath = Server.MapPath("NorthwindCustomers.rpt");
crystalReportViewer.ReportSource = reportPath;
SetDBLogonForReport(connectionInfo);
}
private void Page_Init(object sender, EventArgs e)
{
ConfigureCrystalReports();
}
private void SetDBLogonForReport(ConnectionInfo connectionInfo)
{
TableLogOnInfos tableLogOnInfos = crystalReportViewer.LogOnInfo;
foreach (TableLogOnInfo tableLogOnInfo in tableLogOnInfos)
{
tableLogOnInfo.ConnectionInfo = connectionInfo;
}
}