SpriteHand
Module Border
  ReportViewer Control - Customization at Runtime
Module Border
Location: BlogsAndy's Blog    
Posted by: host 8/30/2006 7:14 AM

Let's say you just created a really cool Report for the .NET 2.0 ReportViewer Control (well, as cool as a report can be anyway).

But wait... At runtime, you want to examine and maybe even change attributes of the report. Like column names, labels, etc.

How do we get at Report properties at runtime?

One way is to tweak the RDLC (Client Report Definition) file before it is fed to the ReportViewer Control. RDLC is based on XML, so we can use XPath queries to find and tweak RDLC properties.

There is a post here that describes this method, and another example below.

First we create a utility function to load in the RDLC and tweak or examine it as necessary...

private TextReader GetCustomRDLC(string rdlcSource)

{

    TextReader readerReport;

    XmlDocument xmlReport = new XmlDocument();

    Stream streamReport;

 

    streamReport = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream(rdlcSource);

 

    xmlReport.Load(streamReport);

 

    XmlNamespaceManager nsManager = new XmlNamespaceManager(xmlReport.NameTable);

    nsManager.AddNamespace("dns", "http://schemas.microsoft.com/sqlserver/reporting/2005/01/reportdefinition");

 

    XmlNodeList nodes = xmlReport.SelectNodes("//dns:Table[@Name='table1']//dns:Details//dns:Textbox", nsManager);

 

    foreach (XmlNode node in nodes)

    {

        System.Diagnostics.Debug.WriteLine(node.Attributes["Name"].Value);

    }

 

    return new StringReader(xmlReport.OuterXml);

 

}

... then we can use this function to feed the ReportViewer Control...

 

 

// create a datasource for the report and set to the datatable dt1

ReportDataSource rds = new ReportDataSource();

rds.Name = "DataSet2_Employees";

dt1.DefaultView.Sort = "FirstName";

rds.Value = dt1.DefaultView;

 

 

 

reportViewer1.LocalReport.DataSources.Clear();

reportViewer1.LocalReport.DataSources.Add(rds);

 

reportViewer1.LocalReport.LoadReportDefinition(GetCustomRDLC("ReportViewerTest.Report2.rdlc"));

 

reportViewer1.RefreshReport();

Permalink |  Trackback

Title:
Comment:
Add Comment   Cancel 
Module Border Module Border
Module Border
  Subscribe
Module Border
RSS   Twitter
Module Border Module Border
Module Border
  Diversions
Module Border

TALKING RAGDOLL
This Windows Phone 7 App was created using Silverlight, the  Physics Helper Library,  and the Farseer Physics Engine. It gets interesting when you import your friends photos and have your way with them!

MORE INFO



DROPPYPOP
This Windows Phone 7 game was created using Silverlight, the  Physics Helper Library,  and the Farseer Physics Engine.
DEMO

MORE INFO



BOSS LAUNCH
This physics game won first place in the Server Quest Contest. Created using Silverlight 2, the Physics Helper Library,  and the Farseer Physics Engine.
PLAY IT

MORE INFO



DESTROY ALL INVADERS
A scrolling shooter game where the objective is to destroy the invading UFO's flying over a neighborhood of your choosing. Imagery provided by Microsoft Virtual Earth. Created using Silverlight 2.
PLAY IT

INFO AND CODE



PHYSICS HELPER DEMOS
These demos were created for the Physics Helper Library, which makes it easy to create physics games and simulations using Expression Blend, Silverlight, and the Farseer Physics Engine.
PLAY IT

INFO AND CODE



HOOK SHOT
This little basketball game took first place in the TeamZoneSports Silverlight Contest. Created using Silverlight 2 and the Farseer Physics engine.
PLAY IT

MORE INFO



SORT THE FOOBARS
A game where you need to sort the good foobars from the bad ones. Created using Silverlight 2 and the Farseer Physics engine.
PLAY IT

MORE INFO



POLYGON PHYSICS DEMO
A demo showing polygon physics where the user draws physics objects with the mouse. Created using Silverlight 2 and the Farseer Physics engine.
PLAY IT

MORE INFO



SILVERLIGHT ROCKS!
Destroy the asteroids before they destroy your ship! Created using Silverlight 2.
PLAY IT

INFO AND CODE



FISH GAME
A simple game of harpoon-the-fish. Written using the AJAX Sprite Toolkit.
PLAY IT

INFO AND CODE

Module Border Module Border
Module Border
  Search_Blog
Module Border
Module Border Module Border
Module Border
  Blog_Archive
Module Border
Module Border Module Border
Copyright (c) 2013 andy.beaulieu.com - Login