How to use session variables in field names of report (.rdcl)

Posted on 2009-12-24
Last Modified: 2012-05-08
Hello, I have a report and need to set a field source depending on a session var. I know the fields I use have to be declared, so I wonder if I can get it to work.


Session("Language") is "de-DE"

In gridview I can evaluate a field like this:
Text='<%# Eval("FieldName" & Session("Language")) %>'

So when I have a column named "Fieldnamede-DE" it will evaluate correctly.

In reportviewer the values are assigned like this:
<Textbox Name="lblProjektBezeichnung">

So my question is:
Is there a way to use something like:
  <Value>=Fields!Fieldname" & Session("Language") & ".Value</Value>

or can I use/write a function that returns the correct value. If so, how and where.
Thank you.

Question by:Stephan_Schrandt
    LVL 10

    Expert Comment

    RDLC report is an XML file that contains the definition of the report such as style and field details. The report can be used in Web and Windows applications. Therefore you cannot use Session variable in the definition. The RDLC is processed by ReportView control and display the actual report. To customise the  field name of TextBox in the RDLC report,  you need to read the RLDC file into XmlDocument, get the XML nodes, update them and assign to ReportViewer.
    Please take a look at thef following link.
    How to dynamically add new columns to report created with Reporting Services?
    LVL 9

    Author Comment

    Heavy load for what I need. If I have to change the fieldnames before the report is accessed in my opinion parameters are the better way. But the main disadvantage is that this will happen outside the report. After doing some research the best option I see so far is the code section of the report.
    LVL 10

    Accepted Solution

    H i Stephan,
    For your scenario, you cannot customise/change field names using parameters and code section. I have also explored the same options before posting my previous post. It seems that we cannot change the field names at run timee using these options. Therefore I suggested to use XmlDocument method to read the content of RDLC file, update it and then load to ReportViewer.
    Ramesh. S

    LVL 9

    Author Comment

    You are right, field names cannot be changes dynamically. My idea was to include all three language columns, add a function that will evaluate the session("language") var then returns the value of the correct column. The problem I faced was accessing the field values by fieldname in the function(besides trusts and all the other things that happen when trying to use other namespaces than the default in reports) . So I will fall back to parameters, because I have over 100 fields in my report and I know about the performance of XML. Anyway, RameshS, you are absolutely right, your answer is the (maybe only) correct solution to my question. Thank you and Merry Christmas :-)

    LVL 9

    Author Closing Comment

    Although I use another way, this is the answer :-)

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Suggested Solutions

    Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
    ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    This video discusses moving either the default database or any database to a new volume.

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    9 Experts available now in Live!

    Get 1:1 Help Now