我在水晶报表中创建了一个报表。它的代码可以正常工作,但我有 1 个问题。例如,如果备注字段为“A”,则应将备注颜色为“红色”,如果结果为“B”,则应将备注颜色为“蓝色”。你能帮帮我吗?这是我的代码。
SqlConnection cnn;
string connectionString = null;
string sql = null;
connectionString = "data source=Server; initial catalog=Database1;user id=sa; password= passw0rd";
cnn = new SqlConnection(connectionString);
cnn.Open();
sql = "select Date as DataColumn1, Name as DataColumn2, Year as DataColumn3 Remarks as DataColumn4 from TableStudents";
SqlDataAdapter dscmd = new SqlDataAdapter(sql, cnn);
cnn.Close();
DataSet1 ds = new DataSet1();
dscmd.Fill(ds, "DataTable1");
CrystalReport1 objRpt = new CrystalReport1();
objRpt.SetDataSource(ds.Tables[0]);
objRpt.ExportToDisk(ExportFormatType.PortableDocFormat, Server.MapPath("Reports.pdf"));
ScriptManager.RegisterStartupScript(base.Page, base.Page.GetType(), "check0", "window.open('" + "Reports.pdf" + "','win2','status=no,toolbar=no,scrollbars=no,titlebar=no,menubar=no,resizable=yes,directories=no,location=no');", true);
此代码将完美地在新窗口中打开报告。只是换颜色的问题。我没有任何想法。请告诉我该怎么办。这是一个简单的概念,但我不知道下一步该做什么。谢谢。
if(result=="A")
{
result.color = "red";
}
else
{
result.color = "blue";
}