• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 687
  • Last Modified:

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

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.

  • 3
  • 2
1 Solution
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?
Stephan_SchrandtAuthor Commented:
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.
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

Stephan_SchrandtAuthor Commented:
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 :-)

Stephan_SchrandtAuthor Commented:
Although I use another way, this is the answer :-)
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now