Click here to Skip to main content
15,884,083 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi everyone,

I want to create a rdlc report with dynamic columns.I mean i want to add or remove columns and also the sort of the columns at runtime in my report.by the way my data is in a datatable.
I have used xmlDocument to load my rdlc file and modify it but an error occured that says something like this : "the data at the root level is invalid".

please tell me how can i do that?
Posted

Hi phoenix1167,
I think you've missed something, check out this below link.

http://dobrzanski.net/2009/02/06/how-to-dynamically-add-new-columns-to-report-created-with-reporting-services/[^]

Hope this helpful.

Regards,
Bluesathish
 
Share this answer
 
Comments
M_Mogharrabi 27-Jan-12 23:58pm    
Hi bluesathish,
Thanks. I've tried the solution of this link too already.but it does not work and i've received that error again.I opened my rdlc report with Notepad but i did not see any Table tag in /Report/Body/ReportItems path...
please guide me.I am too new in using xml files...
M_Mogharrabi 28-Jan-12 4:30am    
Hi,
I've solved that error by the solution of this link "http://stackoverflow.com/questions/310669/why-does-c-sharp-xmldocument-loadxmlstring-fail-when-an-xml-header-is-included".

but now i have another problem!
I have modified my rdlc file in my application but i could not save changes.I've used xmlDocument.Save() method but anything happens...
what is my mistake???
wsc0918 25-Oct-12 21:19pm    
Hi,
I provide my solution when I want to re-save XmlDocument as follow:
System.IO.File.WriteAllText(@"C:\new.rdlc", XmlDocument.InnerXml);
Hope this us useful for you.
M_Mogharrabi 28-Jan-12 23:33pm    
I am waiting for your response please...
Eyval, I have found my response in this link[^]
 
Share this answer
 
Comments
bluesathish 7-Feb-12 0:01am    
good, all the best.
Here I found good example of loading RDLC in runtime, we may also hide columns from codebehind

http://www.mixedresponse.com/Blog/Details/10
 
Share this answer
 
Hi
I had the same situation as like you. So what exactly i have done is:

Create a static RDLC with 25 columns(u may extend).

Hide all the columns by default.

Load the RDLC as XML.

Now collected my run time table columns and replaced the static columns of the RDLC with orginal table columns
example
COl1,COl2,Col3,......Col 25
after getting xml
Col1 should replaced with FirstName, then set as visible
Col2 should replace with LastName, then set as visible
Col3 should replace with Adddresss, then set as visible
like this make the changes for columns.
Similary make a loop for the data of orginal table put the data in the newly created columns,
Now your RDLC will be ready with new columns and fresh data

Now show this report to end user.

One important event you need to implement is RDLC_Unload() in which you need to Reset all your changes ie set Col1,Col2....Col25 remove data etc)

Now check this with the following link
http://lbrtdotnet.wordpress.com/2011/08/12/reporting-services-creating-a-dynamic-column-tablix-report-using-rdl-generator

Thanks
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900