为了账号安全,请及时绑定邮箱和手机立即绑定

DevExpress.XtraReports手动绑定数据只有一个值的问题

DevExpress.XtraReports手动绑定数据只有一个值的问题

临摹微笑 2018-12-06 12:13:35
1.XtraReports Class File: using System;using System.Drawing;using System.Collections;using System.ComponentModel;using DevExpress.XtraReports.UI;/// <summary>/// Summary description for XtraReport1/// </summary>public class XtraReport1 : DevExpress.XtraReports.UI.XtraReport{    private DevExpress.XtraReports.UI.DetailBand Detail;    private DevExpress.XtraReports.UI.TopMarginBand TopMargin;    private DevExpress.XtraReports.UI.BottomMarginBand BottomMargin;    private XRLabel xrLabel1;    private XRLabel xrLabel2;    /// <summary>    /// Required designer variable.    /// </summary>    private System.ComponentModel.IContainer components = null;    public XtraReport1()    {        InitializeComponent();        //        // TODO: Add constructor logic here        //    }        /// <summary>     /// Clean up any resources being used.    /// </summary>    /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>    protected override void Dispose(bool disposing) {        if (disposing && (components != null)) {            components.Dispose();        }        base.Dispose(disposing);    }    #region Designer generated code    /// <summary>    /// Required method for Designer support - do not modify    /// the contents of this method with the code editor.    /// </summary>    private void InitializeComponent() {        string resourceFileName = "XtraReport1.resx";        this.Detail = new DevExpress.XtraReports.UI.DetailBand();        this.TopMargin = new DevExpress.XtraReports.UI.TopMarginBand();        this.BottomMargin = new DevExpress.XtraReports.UI.BottomMarginBand();        this.xrLabel1 = new DevExpress.XtraReports.UI.XRLabel();        this.xrLabel2 = new DevExpress.XtraReports.UI.XRLabel();        ((System.ComponentModel.ISupportInitialize)(this)).BeginInit();        //         // Detail        //         this.Detail.Controls.AddRange(new DevExpress.XtraReports.UI.XRControl[] {            this.xrLabel1});        this.Detail.HeightF = 100F;        this.Detail.Name = "Detail";        this.Detail.Padding = new DevExpress.XtraPrinting.PaddingInfo(0, 0, 0, 0, 100F);        this.Detail.TextAlignment = DevExpress.XtraPrinting.TextAlignment.TopLeft;        //         // TopMargin        //         this.TopMargin.Controls.AddRange(new DevExpress.XtraReports.UI.XRControl[] {            this.xrLabel2});        this.TopMargin.HeightF = 100F;        this.TopMargin.Name = "TopMargin";        this.TopMargin.Padding = new DevExpress.XtraPrinting.PaddingInfo(0, 0, 0, 0, 100F);        this.TopMargin.TextAlignment = DevExpress.XtraPrinting.TextAlignment.TopLeft;        //         // BottomMargin        //         this.BottomMargin.HeightF = 100F;        this.BottomMargin.Name = "BottomMargin";        this.BottomMargin.Padding = new DevExpress.XtraPrinting.PaddingInfo(0, 0, 0, 0, 100F);        this.BottomMargin.TextAlignment = DevExpress.XtraPrinting.TextAlignment.TopLeft;        //         // xrLabel1        //         this.xrLabel1.LocationFloat = new DevExpress.Utils.PointFloat(146.875F, 20.79166F);        this.xrLabel1.Name = "xrLabel1";        this.xrLabel1.Padding = new DevExpress.XtraPrinting.PaddingInfo(2, 2, 0, 0, 96F);        this.xrLabel1.SizeF = new System.Drawing.SizeF(100F, 23F);        this.xrLabel1.Text = "xrLabel1";        //         // xrLabel2        //         this.xrLabel2.Font = new System.Drawing.Font("Times New Roman", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));        this.xrLabel2.LocationFloat = new DevExpress.Utils.PointFloat(25.00002F, 10.00001F);        this.xrLabel2.Name = "xrLabel2";        this.xrLabel2.Padding = new DevExpress.XtraPrinting.PaddingInfo(2, 2, 0, 0, 96F);        this.xrLabel2.SizeF = new System.Drawing.SizeF(615F, 68.16668F);        this.xrLabel2.StylePriority.UseFont = false;        this.xrLabel2.StylePriority.UseTextAlignment = false;        this.xrLabel2.Text = "test";        this.xrLabel2.TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleCenter;        //         // XtraReport1        //         this.Bands.AddRange(new DevExpress.XtraReports.UI.Band[] {            this.Detail,            this.TopMargin,            this.BottomMargin});        this.Version = "9.3";        ((System.ComponentModel.ISupportInitialize)(this)).EndInit();    }    #endregion} 2.page File: using System;using System.Collections.Generic;using DevExpress.XtraReports.UI;public partial class _Default : System.Web.UI.Page {    protected void Page_Load(object sender, EventArgs e)    {        XtraReport1 rpt = new XtraReport1();        this.ReportViewer1.Report = rpt;        XRLabel lbl = (XRLabel)rpt.FindControl("xrLabel2", true);        List<Student> stulst = new List<Student>();        for (int i = 0; i < 50; i++)        {            Student stu = new Student();            stu.Name = "name" + i;            stulst.Add(stu);        }        rpt.Bands[BandKind.Detail].Controls.Add(lbl);        lbl.DataBindings.Add("Text", stulst, "Name");            }    class Student    {        string name;        public string Name        {            get { return name; }            set { name = value; }        }        string sex;        public string Sex        {            get { return sex; }            set { sex = value; }        }    }} 3.结果是这个xrLabel2在页面上只有一个值name0,而期望的结果应该是50条记录,请高手指点,多谢! 4.手动绑定时,不同的控件如何绑定不同的数据源?(因为绑定时要report.datasource=list)
查看完整描述

4 回答

?
慕标琳琳

TA贡献1830条经验 获得超9个赞

有个自动生成列的属性,我用过winform的版本。

查看完整回答
反对 回复 2019-01-21
?
回首忆惘然

TA贡献1847条经验 获得超11个赞

仍然只显示一条记录啊

查看完整回答
反对 回复 2019-01-21
?
隔江千里

TA贡献1906条经验 获得超10个赞

加一句代码:

DataSource = dt;(dt为DataTable,数据源)

查看完整回答
反对 回复 2019-01-21
  • 4 回答
  • 0 关注
  • 1255 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信