zoukankan      html  css  js  c++  java
  • XtraReport三动态数据绑定

    代码还用上一节的,把Report的Datasource去掉。各个绑定的字段也去掉,有了第二节的基础,现在看这个就不难了,无非就是传到report一个数据集,在把这个数据集绑定到各控件里 清空details里的Cell的值,各cell改成数据库对应列的名字方便绑定

    XReport 代码如下 作用就是绑定一下数据

      XREPORT代码在设计器界面右键显示

      public XtraReport1(DataTable dt)
            {
                InitializeComponent();
                this.DataSource = dt;
                //这里面的Text是xrtable的属性 区分大小写
                this.xrTableCell1.DataBindings.Add("Text",dt,"bid");
                this.xrTableCell2.DataBindings.Add("Text", dt, "bname");
                this.xrTableCell3.DataBindings.Add("Text", dt, "shuoming");
                this.xrTableCell4.Text = "编号";
                this.xrTableCell5.Text = "名称";
                this.xrTableCell6.Text = "备注";
                
            }

    Form1代码如下

       private void button1_Click(object sender, EventArgs e)
            {
                DataTable dt = new DataTable();
                string constr = "server=192.168.100.222;user=sa;pwd=p@ssw1rd;database=pwd1";
                SqlConnection con = new SqlConnection(constr);
                try
                {
                    con.Open();
                    SqlCommand com = new SqlCommand("select bid,bname,shuoming from book",con);
                    SqlDataAdapter dpt = new SqlDataAdapter(com);
                    dpt.Fill(dt);
                    XtraReport1 report = new XtraReport1(dt);
                    report.Landscape = true;
                    documentViewer1.DocumentSource = report;
                    report.CreateDocument();
                }
                catch (Exception)
                {
                    
                    throw;
                }
            }

    理解:

          只有在datalis下面才能显示多行数据,Reportheader只是报表的头部。

      Xrtable  建立在datalis下面,form 下添加控件有splitcontrol 作为容器 dock属性为fill ,documentview 属性dock=fill, navbarcontrol 导航窗体,FORM1属性 windowsstate 设置max最大化

  • 相关阅读:
    VUE可随意拖动的弹窗组件
    入园仪式
    Node启动https服务器
    《高性能javascript》阅读摘要
    浏览器HTTP缓存机制
    使用nightwatch进行E2E测试中文教程
    Puppeteer的入门教程和实践
    Spring AOP 笔记
    ApplicationContext国际化的支持
    Spring ApplicationContext中的”事件传递“笔记
  • 原文地址:https://www.cnblogs.com/xiaowie/p/8970709.html
Copyright © 2011-2022 走看看