[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 668
  • 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.

e.g.:

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">
  ....
  <Value>=Fields!Fieldname.Value</Value>
</Textbox>

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.




0
Stephan_Schrandt
Asked:
Stephan_Schrandt
  • 3
  • 2
1 Solution
 
RameshSCommented:
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?
 
0
 
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.
0
 
RameshSCommented:
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.
Regards
Ramesh. S


 
0
 
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 :-)

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

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

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