Solved

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

Posted on 2012-04-12
17
651 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
Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

 
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 500 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

Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

Question has a verified solution.

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

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

749 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