William 的个人资料.Net Zone日志列表 工具 帮助
2月20日

ReportViewer with nested tables

Sometimes you may need a report that can not be done easily with standard grouping in a table.  Say you want to a repeatable data region that is repeated by an outer group, but contains two other tables an maybe an image.  I can't think of a good way to do that with standard row grouping using a tablix.  However, the List control makes this easy.  In short, here is what is needed.  A List control that contains all other elements and is grouped by some value.  The List gets repeated for each unique group value.  Put two Tables in the List and toss in any other controls you need such as Textboxes or Images.

Here is the controls layed out in Visual Studio report designer:

image

 

We get our data from the database using anything such as Linq or other.  However, we "flatten" it because reports do not understand nested data.

We can make developing the report simplier by skipping the DB step and making our own objects like:

public class Offers
{
    public string OfferID { get; set; }
    public string Offerer { get; set; }
    public bool IsProgram { get; set; }
    public string ProgramName { get; set; }
    public int ProgramHours { get; set; }
    public bool IsPrereq { get; set; }
    public string PrereqName { get; set; }
    public int PrereqCode { get; set; }
    public byte[] Image { get; set; } 

    public static List<Offers> GetData()
    {
        byte[] im = File.ReadAllBytes(@"C:\Users\William\Pictures\MarkTwain.jpg");
        byte[] im2 = File.ReadAllBytes(@"c:\users\william\pictures\captain_john_smith.jpg"); 

        // Offer1
        Offers of1 = new Offers(){ OfferID="03453", Offerer="John Smith", IsProgram=true, ProgramName="admission", ProgramHours=1};
        of1.Image = im2;
        Offers of2 = new Offers(){ OfferID="03453", Offerer="John Smith", IsProgram=true, ProgramName="actual crisis", ProgramHours=10};
        of2.Image = im2;
        Offers of3 = new Offers(){ OfferID="03453", Offerer="John Smith", IsProgram=true, ProgramName="discussion", ProgramHours=5};
        of3.Image = im2;
        Offers of4 = new Offers(){ OfferID="03453", Offerer="John Smith", IsProgram=true, ProgramName="final notes", ProgramHours=2};
        of4.Image = im2; 

        Offers of5 = new Offers(){ OfferID="03453", Offerer="John Smith", IsPrereq=true, PrereqName="Macro econ II", PrereqCode=3463};
        of5.Image = im2;
        Offers of6 = new Offers(){ OfferID="03453", Offerer="John Smith", IsPrereq=true, PrereqName="Finance", PrereqCode=34634};
        of6.Image = im2;
        List<Offers> offers = new List<Offers>() {of1, of2, of3, of4, of5, of6}; 

        // Offer2
        of1 = new Offers(){ OfferID="80345", Offerer="Mark Twain", IsProgram=true, ProgramName="admission2", ProgramHours=2};
        of1.Image = im;
        of2 = new Offers(){ OfferID="80345", Offerer="Mark Twain", IsProgram=true, ProgramName="actual crisis2", ProgramHours=3};
        of2.Image = im;
        of3 = new Offers(){ OfferID="80345", Offerer="Mark Twain", IsProgram=true, ProgramName="discussion2", ProgramHours=4};
        of3.Image = im;
        of4 = new Offers(){ OfferID="80345", Offerer="Mark Twain", IsProgram=true, ProgramName="final notes2", ProgramHours=7};
        of4.Image = im; 

        of5 = new Offers(){ OfferID="80345", Offerer="Mark Twain", IsPrereq=true, PrereqName="Macro econ II2", PrereqCode=3466};
        of5.Image = im;
        of6 = new Offers(){ OfferID="80345", Offerer="Mark Twain", IsPrereq=true, PrereqName="Finance2", PrereqCode=34638};
        of6.Image = im;
        List<Offers> offers2 = new List<Offers>(){of1, of2, of3, of4, of5, of6};
        offers.AddRange(offers2);
        return offers;
    }
}

 

Now in the Report load event of your report Form do something like:

private void Offers_Load(object sender, EventArgs e)
{
    var list = Offers.GetData();
    this.OffersBindingSource.DataSource = list;
    this.reportViewer1.LocalReport.EnableExternalImages = true;
    this.reportViewer1.RefreshReport();
}

 

Now you have a report that has grouped "regions" and inside each region can contain other lists and/or other elements related to the group.

Output:

image

评论 (3)

请稍候...
很抱歉,您输入的评论太长。请缩短您的评论。
您没有输入任何内容,请重试。
很抱歉,我们当前无法添加您的评论。请稍后重试。
若要添加评论,需要您的家长授予您相应权限。请求权限
您的家长禁用了评论功能。
很抱歉,我们当前无法删除您的评论。请稍后重试。
您已超过了一天之内允许提供的评论数上限。请在 24 小时后重试。
因为我们的系统表明您可能在向其他用户提供垃圾评论,您的帐户已禁用了评论功能。如果您认为我们错误地禁用了您的帐户,请联系 Windows Live 支持部门
完成下面的安全检查,您提供评论的过程才能完成。
您在安全检查中键入的字符必须与图片或音频中的字符一致。

若要添加评论,请使用您的 Windows Live ID 登录(如果您使用过 Hotmail、Messenger 或 Xbox LIVE,您就拥有 Windows Live ID)。登录


还没有 Windows Live ID 吗?请注册

没有名字发表:
http://www.batteryfast.com.au/toshiba/pa3534u-1brs.htm toshiba pa3534u-1brs battery ,
http://www.batteryfast.com.au/toshiba/satellite-a205.htm toshiba satellite a205 battery ,
http://www.batteryfast.com.au/uniwill/un223.htm uniwill un223 battery ,
http://www.batteryfast.com.au/uniwill/223-3s4000-f1p1.htm uniwill 223-3s4000-f1p1 battery ,
http://www.batteryfast.com.au/uniwill/223-3s4000-s1p1.htm uniwill 223-3s4000-s1p1 battery ,
http://www.batteryfast.com.au/uniwill/bat-243s1.htm uniwill bat-243s1 battery ,
http://www.batteryfast.com.au/uniwill/un243.htm uniwill un243 battery ,
http://www.batteryfast.com.au/uniwill/un244.htm uniwill un244 battery ,
http://www.batteryfast.com.au/uniwill/255-3s4400-g1l1.htm uniwill 255-3s4400-g1l1 battery ,
http://www.batteryfast.com.au/uniwill/un255.htm uniwill un255 battery ,
http://www.batteryfast.com.au/uniwill/un258.htm uniwill un258 battery ,
http://www.batteryfast.com.au/uniwill/258-4s4400-s1p1.htm uniwill 258-4s4400-s1p1 battery ,
http://www.batteryfast.com.au/uniwill/258-4s4400-s2m1.htm uniwill 258-4s4400-s2m1 battery ,
http://www.batteryfast.com.au/uniwill/755-4s4000-s1p1.htm uniwill 755-4s4000-s1p1 battery ,
http://www.batteryfast.com.au/uniwill/un755.htm uniwill un755 battery ,
http://www.batteryfast.com.au/acer/2420.php acer BTP-ARJ1 2420 series laptop battery ,
http://www.batteryfast.com.au/acer/as07b72-battery.php Battery Fit Aspire 5520 5920 Series AS07B72 laptop battery ,
http://www.batteryfast.com.au/acer/batcl50l.php acer travelmate 290 291 29x 292 batcl50l laptop battery ,
http://www.batteryfast.com.au/acer/batecq60.php acer 1800 series batecq60 laptop battery ,
http://www.batteryfast.com.au/acer/batefl50l6c40-battery.php Battery For Aspire 5030 5050 5500 5550 5570 5580 laptop battery ,
http://www.batteryfast.com.au/acer/btp-39d1.php acer btp-620 btp-39d1 btp-39sn ms2103 laptop battery ,
http://www.batteryfast.com.au/acer/btp-43d1.php acer travelmate 22x 23x 26x 28x btp-43d1 laptop battery ,
http://www.batteryfast.com.au/acer/btp-550.php acer btp-550p btp-550 bat30n3l batby27l laptop battery ,
http://www.batteryfast.com.au/acer/btp-73e1.php acer travelmate 370 380 btp-73e1 btp-50t3 laptop battery ,
http://www.batteryfast.com.au/acer/btp-agd1.php acer btp-63d1 btp-agd1 3020 3610 laptop battery ,
http://www.batteryfast.com.au/acer/lcbtp03003.php New battery fit Acer LIP-4084QUPC SQU-401 5000 laptop battery ,
http://www.batteryfast.com.au/acer/tm3002-battery.php New Battery Acer TravelMate 3002WTCi 3002WTMi laptop battery ,
http://www.batteryfast.com.au/acer/tm3200e.php laptop battery for 3UR18650F-3-QC151 tm3200 laptop battery ,
http://www.batteryfast.com.au/acer/tm4200.php Battery ACER BATBL50L6 Travelmate 4200 4203 4230 4260 4280 laptop battery ,
http://www.batteryfast.com.au/acer/um08a71.php Black Battery for Acer Aspire One UM08A71 UM08A72 UM08A73 NEW laptop battery ,
http://www.batteryfast.com.au/acer/um08a72.php Blue Battery for Acer Aspire One UM08B71 UM08B72 UM08B73 NEW laptop battery ,
http://www.batteryfast.com.au/acer/um08a73.php white Battery for Acer Aspire One ZG5 NEW laptop battery ,
http://www.batteryfast.com.au/acer/um08a74.php Black Battery for Aspire One A110 NEW laptop battery ,
http://www.batteryfast.com.au/acer/um08b72.php Blue Battery for Acer Aspire One 150L NEW laptop battery ,
http://www.batteryfast.com.au/acer/um08b73.php white Battery for Acer Aspire One 150X NEW laptop battery ,
http://www.batteryfast.com.au/apple/a1022.php apple powerbook g4 a1022 a1079 m9324 laptop battery ,
http://www.batteryfast.com.au/apple/a1078.php apple a1045 a1078 e68043 m9325 m9756 laptop battery ,
http://www.batteryfast.com.au/apple/A1175.php apple A1175 Macbook Pro 15-4 laptop battery ,
http://www.batteryfast.com.au/apple/a1185.php NEW Hi-Cap 5500mAh Battery for MacBook 13 A1185 WHITE laptop battery ,
http://www.batteryfast.com.au/apple/a1185-2.php NEW Hi-Cap 5500mAh Battery for MacBook 13 A1185 black laptop battery ,
http://www.batteryfast.com.au/asus/90-n901b1000.php asus W1 W1000 A42-W1 W1G W1Ga laptop battery ,
http://www.batteryfast.com.au/asus/a42-w1.php asus W1 W1000 A42-W1 W1G W1Ga laptop battery ,
http://www.batteryfast.com.au/asus/90-nca1b2000.php asus A42-W3 W3A W3N W3V W3000 W3000A grey laptop battery ,
http://www.batteryfast.com.au/asus/a3000.php asus a42-a3 a3000 z9100 a3l a3n laptop battery ,
http://www.batteryfast.com.au/asus/a31-s5.php ASUS A31-S5 A32-S5 S52N S5000 S5200N S5N laptop battery ,
http://www.batteryfast.com.au/asus/a31-s5-2.php ASUS A31-S5 A32-S5 S52N S5000 S5200N S5N laptop battery ,
http://www.batteryfast.com.au/asus/a32-f3.php A32-F3 Battery ASUS F3 F3J F3Q F3JA F3JM F3JF Hi-Capaci laptop battery ,
http://www.batteryfast.com.au/asus/a42-a2-battery.php A42-A2 Battery to ASUS A2C A2D A2000 A2500H A2S A2K Z80 laptop battery ,
http://www.batteryfast.com.au/asus/a42-a4.php asus a4 a4d a4g a4k a4l a4s a4000 a42-a4 laptop battery ,
3 月 10 日
You saved my life :)
3 月 9 日
没有名字发表:
hi
thanks for the gr8 post. i cant figure out what this "OffersBindingSource" is

<%@ Page Language="VB" CodeFile="try.aspx.vb" Inherits="Reports_try" %>

<%@ Register Assembly="Microsoft.ReportViewer.WebForms, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
Namespace="Microsoft.Reporting.WebForms" TagPrefix="rsweb" %>
<html>
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<rsweb:ReportViewer ID="ReportViewer1" runat="server">
<LocalReport ReportPath="Report1.rdlc">
<DataSources>
<rsweb:ReportDataSource DataSourceId="ObjectDataSource1" Name="MainBaseDataSet_viwPersons" />
</DataSources>
</LocalReport>
</rsweb:ReportViewer>
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" SelectMethod="GetData"
TypeName="MainBaseDataSetTableAdapters.viwPersonsTableAdapter"></asp:ObjectDataSource>
</div>
</form>
</body>
</html>

i cannot find any datasource object, except for the datasources collection of the report. is that what u mean? cant seem to set it via code

i have a linq object that im trying to hook up to a report. coud be microsft or crystal. both seem very powerful, just wanna get started with this. thanks
2 月 26 日

引用通告

引用此项的网络日志