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)
慕标琳琳
回首忆惘然
隔江千里