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最大化

  • 相关阅读:
    19. vue的原理
    18.jwt加密
    17.vue移动端项目二
    16.vue-cli跨域,swiper,移动端项目
    15.vue动画& vuex
    14.vue路由&脚手架
    13.vue组件
    12.vue属性.监听.组件
    11.vue 数据交互
    从尾到头打印链表
  • 原文地址:https://www.cnblogs.com/xiaowie/p/8970709.html
Copyright © 2011-2022 走看看