商务合作:179001057@qq.com

水晶报表 用户 自定义字段 加 (动态边框)

技术2022-05-11  0


某平台价值19860元的编程课程资料免费领取【点我领取】


在实现用户自定义字段前,先往源码中添加几个checkBox控件,和一个Button,再加一个报表的 CrystalReportViewer

 

结果如图:

 

然后往报表中添加几个参数:

http://www.cnblogs.com/babyt/articles/142908.html跟阿泰的参数一样的!

 

并设置各个公式的边框的背景颜色,记住各个公式的值都是空的!

具体如图:

 

运行结果如图:

 

 

 

 

代码是这样的,不过要记住,在做真正项目时要把代码放进 protected void Page_Load(object sender, EventArgs e)    {

    }

中这样就可以查看下一页的信息了:

using System;using System.Collections;using System.Configuration;using System.Data;using System.Linq;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.HtmlControls;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Xml.Linq;using System.Data.SqlClient;using CrystalDecisions.CrystalReports.Engine;using CrystalDecisions.Shared;using CrystalDecisions.CrystalReports;

public partial class CRport3 : System.Web.UI.Page{

    DB db = new DB();

    protected void Page_Load(object sender, EventArgs e)    {

    }    protected void Button1_Click(object sender, EventArgs e)    {        //String cnstr = "";        //保持字段的字符串         String fldstr = "";        //保持字段名称的数组        String[] fldArr = new string[6];        int i = 0;        int j = 0;        //获取选取的字段并进行处理         if (checkBox1.Checked == true)        {            fldstr = fldstr + "," + checkBox1.ToolTip;        }        if (checkBox2.Checked == true)        {            fldstr = fldstr + "," + checkBox2.Text;        }        if (checkBox3.Checked == true)        {            fldstr = fldstr + "," + checkBox3.Text;        }        if (checkBox4.Checked == true)        {            fldstr = fldstr + "," + checkBox4.Text;        }        if (checkBox5.Checked == true)        {            fldstr = fldstr + "," + checkBox5.Text;        }        if (checkBox6.Checked == true)        {            fldstr = fldstr + "," + checkBox6.Text;        }        if (fldstr == "")        {

            Response.Write("<script language='javascript'>alert('请选择要显示的字段!');</script>");            return;        }        if (fldstr.Substring(0, 1) == ",")        {            fldstr = fldstr.Substring(1, fldstr.Length - 1);        }        fldArr = fldstr.Split(new Char[] { ',' });        db.Open();

        string sql = "";        sql = " Select " + fldstr + " From Employee";//--------------------------------------

        SqlDataAdapter da1 = new SqlDataAdapter(sql, db.Open());

        DataSet ds1 = new DataSet();        da1.Fill(ds1, "Employee");

        ReportDocument crReportDocument = new ReportDocument();        crReportDocument.Load(Server.MapPath("CRport3.rpt"));

        //-------------------------        for (i = 0; i < fldArr.Length; i++)        {

            // 将公式绑定到具体字段                 crReportDocument.DataDefinition.FormulaFields["mf" + (i + 1).ToString()].Text = "{Employee." + fldArr[i] + "}";            crReportDocument.DataDefinition.FormulaFields["mt" + (i + 1).ToString()].Text = "/"" + fldArr[i] + "/"";

          

        }

        for (j = i + 1; j <= 6; j++)        {            crReportDocument.DataDefinition.FormulaFields["mt" + (j).ToString()].Text = "";        }

        crReportDocument.SetDataSource(ds1);

        CrystalReportViewer1.ReportSource = crReportDocument;    }}

 

 

 

了解具体的报表情况请看 阿泰的水晶报表,他做的挺不错的!

http://www.cnblogs.com/babyt/articles/142908.html

 

对了一定要把源中的 <%--<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">--%>把它隐掉,这样就可以就可以看到了


最新回复(0)