Devexpress_Lable Report 绑定数据

首先新建一个报表项目,并设置报表纸张大小、页边距等信息;


根据需要,设计报表的布局;

完成布局设计后,绑定数据源。在此利用代码绑定数据源;

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using DevExpress.XtraReports.UI;
using System.Data;
using BaseUI.BaseClass;

namespace LYWJMIS
{
    public partial class XtraReport1 : DevExpress.XtraReports.UI.XtraReport
    {
        public XtraReport1()
        {
            InitializeComponent();
        }
        /// <summary>
        /// 带参数的构造函数
        /// </summary>
        /// <param name="ds">要绑定的数据集</param>
        public XtraReport1(DataSet ds): this()
        {
            if (!FormAssistant.IsDsNull(ds))
            {
                this.DataSource = ds;
                this.DataMember = "Table1";
                FillControlValue(ds);
            }
        }
        private void FillControlValue(DataSet ds)
        {
            //为XRLable绑定数据集及对应的字段
            this.txtDB0005A.DataBindings.Add("Text",ds,"DB0005A");
            this.txtDB0336A.DataBindings.Add("Text",ds,"DB0336A");
            this.txtDB0337A.DataBindings.Add("Text",ds,"DB0337A");
            this.txtDB0339A.DataBindings.Add("Text",ds,"DB0339A");
            this.txtDB0345A.DataBindings.Add("Text",ds,"DB0345A");
        }
    }
}

数据绑定后,调用报表,打印预览;

 private void btnPrint_Click(object sender, EventArgs e)
        {
            XtraReport1 rep = new XtraReport1(dsSearch);
            //设置纸张类型为自定义
            rep.PaperKind = System.Drawing.Printing.PaperKind.Custom;
            //设置纸张大小,单位:像素
            double width = 302;
            double height = 199;
            rep.PageSize = new System.Drawing.Size((int)width, (int)height);
            //打印预览
            rep.ShowPreview();
        }




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值