Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Help with passing value from textbox in ASPX page to a MS report

Posted on 2012-04-12
17
Medium Priority
?
663 Views
Last Modified: 2012-06-27
Hello,

I need to modify the color of a textbox in my report depending on the values entered in a textbox on my form. How do i achieve this?

For example I would like to set the Background color of my  report's Textbox to red if the user
enter BEL in the APSX's form's textbox.

Thanks,

Victor
0
Comment
Question by:vcharles
17 Comments
 
LVL 16

Expert Comment

by:MikeMCSD
ID: 37840608
if (txt1.Text == "BEL")
            {
                txt1.BackColor = System.Drawing.Color.Red;
            }
0
 

Author Comment

by:vcharles
ID: 37840866
I'm afraid this code would not work. I need to pass the value entered in textbox1.text of my asps form to my report and modify the background color of textbox2.text in my report.
0
 

Author Comment

by:vcharles
ID: 37840898
Hi,

For example I need to modify the code below for it to work with the report.

Textbox1 on in the aspx form
Textbox2 is on the MS Report

If Textbox2.text = Textbox1.text then
Textbox2.backcolor = "red"
endif
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 29

Expert Comment

by:Kumaraswamy R
ID: 37841302
rptMyReport report = new rptMyReport();
TextObject to = (TextObject)report.ReportDefinition.Sections["Section2"].ReportObjects["textboxname"];
to.Text = newvalue;
0
 

Author Comment

by:vcharles
ID: 37841469
Hi,

Can you please explain the code to me. I can't figure out where you are taking the value entered in Textbox1.Text (from the aspx form).
Also how are you changing the background color of Textbox2.text (from RDLC) when Textbox1.Text = Texbox2.Text?

Thanks.
0
 
LVL 12

Expert Comment

by:Harish Varghese
ID: 37843970
Hello Victor,

Your approach should be as follows:

1. Take the Color mentioned by the user in ASPX form.
2. Pass it as a parameter to your Report
3. In your report, use this parameter to set background colors to the required textboxes/cells.

Please read below link to see how parameters are passed to Report from ASPX:
http://www.codeproject.com/Articles/15469/Integrating-Reporting-Services-2005-Into-a-Web-App

By the way, were you able to create parameters for colors and use them for cells inside report?

Thanks,
Harish
0
 

Author Comment

by:vcharles
ID: 37844001
Hi,

I am still confused, will look at  the link and get back to you.

For example when you say

1. Take the Color mentioned by the user in ASPX form.

I am not sure what you mean because the color with depend on the text in Report's texbox,  for example if:

Textbox1 on in the aspx form
Textbox2 is on the MS Report

If Textbox2.text = Textbox1.text then
Textbox2.backcolor = "red"
endif

Victor
0
 
LVL 12

Expert Comment

by:Harish Varghese
ID: 37844148
Victor,

I thought you wanted to pass the color to the report. Ok, read the points as below:

1. Take the value in TextBox1 in ASPX form.
2. Pass it as a parameter to your Report
3. In your report, use this parameter to compare values in the cells and set background color to the required textboxes/cells.


Thanks,
Harish
0
 

Author Comment

by:vcharles
ID: 37844632
Got it, will look at the links to figure out how to do steps 2 and 3, if can't still can't figure it out, I will ask for more help.
0
 

Author Comment

by:vcharles
ID: 37844807
Hi,

Below is the code in C# to pass the value of the Textbox as a parameter to the report, but I still can figure out how to use it to set the value of the textbox that is in the report, can you please help me with the propoer syntax in VB.NET


Button_Click event:

Dim textcolor as string
textcolor = Textbox1.Text

RptParameters[0] =
    new Microsoft.Reporting.WebForms.ReportParameter("TextboxColor", textcolor);
this.ReportViewer1.ServerReport.SetParameters(RptParameters);
this.ReportViewer1.ServerReport.Refresh();
0
 
LVL 12

Expert Comment

by:Harish Varghese
ID: 37847630
Victor,

You are again confusing me!
Dim textcolor as string
textcolor = Textbox1.Text

That means you want to pass the name of the color to the report.
Anyway, let me see if I can make a sample report and aspx code for you.

Thanks,
Harish
0
 

Author Comment

by:vcharles
ID: 37847809
Hi,

Textcolor was not a propoer name to use, I am trying to pass for example the country and see if it matches the value of the textbox in the report, for example if user Enters BEL, change the color in the report if textbox in report = BEL

Dim CountryText as string
CountryText = Textbox1.Text

RptParameters[0] =
    new Microsoft.Reporting.WebForms.ReportParameter("TextboxColor", CountryText);
this.ReportViewer1.ServerReport.SetParameters(RptParameters);
this.ReportViewer1.ServerReport.Refresh();

Thanks,

V.
0
 

Author Comment

by:vcharles
ID: 37847824
Hi again,

I need to resolve the single entry first, but in some cases if the user enters BEL,CAN,USA, I need to somehow change the color for all the entries, for example, If textbox in report IN ( Textbox1.Text)  where Texbox.text = BEL,CAN,USA, change the color in the report if textbox in report = BEL or CAN, or USA. Thanks for working on a small report.
0
 
LVL 12

Expert Comment

by:Harish Varghese
ID: 37850555
Hello Victor,

Have you deployed your report on a server? In that case, here is the code to pass a parameter to the report and retrieve the report.

1. I created ASPX file with a Report Viewer.
2. Below is the code I used for the button to retrieve the report:
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
        Dim textcolor As String = TextBox1.Text
        Dim RptParameters As Microsoft.Reporting.WebForms.ReportParameter() = New Microsoft.Reporting.WebForms.ReportParameter(1) {}

        'Initialize report
        ReportViewer1.ProcessingMode = Microsoft.Reporting.WebForms.ProcessingMode.Remote
        ReportViewer1.ServerReport.ReportServerUrl = New Uri("http://harishv-l057/ReportServer_SQL2008R2") ' Report Server URL 
        ReportViewer1.ServerReport.ReportPath = "/TextColor Example" ' Report Name 
        ReportViewer1.ShowParameterPrompts = False
        ReportViewer1.ShowPrintButton = True

        'Assign values to parameters
        RptParameters(0) = New Microsoft.Reporting.WebForms.ReportParameter("TextboxColor1", textcolor)
        RptParameters(1) = New Microsoft.Reporting.WebForms.ReportParameter("TextboxColor2", "LightGreen")

        'Retrieve report
        Me.ReportViewer1.ServerReport.SetParameters(RptParameters)
        Me.ReportViewer1.ServerReport.Refresh()

    End Sub

Open in new window


I have attached the report file and the Default.aspx file I used.

Here is a useful link that shows how to call SSRS report from ASPX. Please read it, it is very simple.
http://forums.asp.net/t/1281716.aspx/1

And here is another link to convert c# code to VB.Net easily:
http://www.developerfusion.com/tools/convert/csharp-to-vb/

Thanks,
Harish
Default.aspx
Default.aspx.vb
Default.aspx.designer.vb
TextColor-Example.rdl
0
 

Author Comment

by:vcharles
ID: 37850819
Harish,

I modified your code for the Windows version, but I'm not certain how you are passing the value to the report, the name of the textbox of the report is TxtReceiver. Where do I include it in the code?


What does the following code do?

      RptParameters(0) = New Microsoft.Reporting.WinForms.ReportParameter("TextboxColor1", textcolor)
        RptParameters(1) = New Microsoft.Reporting.WinForms.ReportParameter("TextboxColor2", "LightGreen")


Complete code:



    Dim dt As New DataTable()
        dt.TableName = "Links"
        dt.Columns.Add("Link_ID")
        dt.Columns.Add("Receiver")
        dt.Columns.Add("Donor")
    Dim linker As XElement = XElement.Load(Application.StartupPath + "\Link.xml")
    Dim receiver As XElement = XElement.Load(Application.StartupPath + "\Receiver.xml")
    Dim Donor As XElement = XElement.Load(Application.StartupPath + "\Donor.xml")
        For Each item As XElement In linker.Elements("Row")

    Dim linkID As String = item.Element("Link_ID").Value
    Dim receiverId As String = item.Element("Receiver_ID").Value
    Dim DonorID As String = item.Element("Donor_ID").Value 'Add (3)
    Dim receiverVal As String = String.Empty
    Dim xe As XElement = receiver.Elements("Row").Cast(Of XElement)().Where(Function(n) n.Element("Receiver_ID").Value = receiverId).FirstOrDefault()
            If xe IsNot Nothing Then
                receiverVal = xe.Element("Receiver").Value
            End If
    Dim DonorVal As String = String.Empty
            xe = Donor.Elements("Row").Cast(Of XElement)().Where(Function(n) n.Element("Donor_ID").Value = DonorID).FirstOrDefault()
            If xe IsNot Nothing Then
                DonorVal = xe.Element("Donor").Value
            End If
    Dim dr As DataRow = dt.NewRow()
            dr("Link_ID") = linkID
            dr("Receiver") = receiverVal
            dr("Donor") = DonorVal 'Add (5)
            dt.Rows.Add(dr)
        Next
    Dim bs As New BindingSource()
        bs.DataSource = dt

        'View Report

        Dim textcolor As String = TextBox1.Text
        Dim RptParameters As Microsoft.Reporting.WinForms.ReportParameter() = New Microsoft.Reporting.WinForms.ReportParameter(1) {}

        Dim reportDataSource As New Microsoft.Reporting.WinForms.ReportDataSource()
        reportDataSource.Name = "MyDataSet_Links"
        reportDataSource.Value = dt

        RptParameters(0) = New Microsoft.Reporting.WinForms.ReportParameter("TextboxColor1", textcolor)
        RptParameters(1) = New Microsoft.Reporting.WinForms.ReportParameter("TextboxColor2", "LightGreen")



        ReportViewer1.LocalReport.DataSources.Add(reportDataSource)
        ReportViewer1.LocalReport.SetParameters(RptParameters)
        ReportViewer1.LocalReport.Refresh()
        ReportViewer1.RefreshReport()


Thanks.
0
 
LVL 12

Accepted Solution

by:
Harish Varghese earned 2000 total points
ID: 37857124
Hello Victor,

You will not be controlling color of textboxes within report from the ASPX page.
Below code passes two parameters to your report. TextboxColor1 and TextboxColor2 are two input parameters defined in the report. This parameters will be used to control background colors of textboxes/table cells inside the report.

RptParameters(0) = New Microsoft.Reporting.WinForms.ReportParameter("TextboxColor1", textcolor)
        RptParameters(1) = New Microsoft.Reporting.WinForms.ReportParameter("TextboxColor2", "LightGreen")

You will get many tutorials about using parameters in SSRS report. Below are few basic links:
http://msdn.microsoft.com/en-us/library/aa337432.aspx

http://msdn.microsoft.com/en-us/library/ms155917(v=sql.90).aspx

Thanks,
Harish
0
 

Author Comment

by:vcharles
ID: 37857313
Got it. Thank You very much.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hi, I have heard from my friends that it’s not possible to create Label Printing report using SSRS. I am amazed after hearing this words not possible in SSRS. I googled lot and found that it is possible to some of people know about the Report Bui…
Introduction In the following article I’ll be discussing and demonstrating several different ways of how images can be put on a report. I’m using SQL Server Reporting Services 2008 R2 CTP, more precisely version 10.50.1352.12, but the methods ex…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

916 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