Victor Charles
asked on
Help with passing value from textbox in ASPX page to a MS report
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
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
ASKER
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.
ASKER
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
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
rptMyReport report = new rptMyReport();
TextObject to = (TextObject)report.ReportD efinition. Sections[" Section2"] .ReportObj ects["text boxname"];
to.Text = newvalue;
TextObject to = (TextObject)report.ReportD
to.Text = newvalue;
ASKER
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.
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.
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
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
ASKER
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
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
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
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
ASKER
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.
ASKER
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.WebFor ms.ReportP arameter(" TextboxCol or", textcolor);
this.ReportViewer1.ServerR eport.SetP arameters( RptParamet ers);
this.ReportViewer1.ServerR eport.Refr esh();
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.WebFor
this.ReportViewer1.ServerR
this.ReportViewer1.ServerR
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
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
ASKER
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.WebFor ms.ReportP arameter(" TextboxCol or", CountryText);
this.ReportViewer1.ServerR eport.SetP arameters( RptParamet ers);
this.ReportViewer1.ServerR eport.Refr esh();
Thanks,
V.
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.WebFor
this.ReportViewer1.ServerR
this.ReportViewer1.ServerR
Thanks,
V.
ASKER
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.
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.
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:
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
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
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
ASKER
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.WinFor ms.ReportP arameter(" TextboxCol or1", textcolor)
RptParameters(1) = New Microsoft.Reporting.WinFor ms.ReportP arameter(" TextboxCol or2", "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. StartupPat h + "\Link.xml")
Dim receiver As XElement = XElement.Load(Application. StartupPat h + "\Receiver.xml")
Dim Donor As XElement = XElement.Load(Application. StartupPat h + "\Donor.xml")
For Each item As XElement In linker.Elements("Row")
Dim linkID As String = item.Element("Link_ID").Va lue
Dim receiverId As String = item.Element("Receiver_ID" ).Value
Dim DonorID As String = item.Element("Donor_ID").V alue 'Add (3)
Dim receiverVal As String = String.Empty
Dim xe As XElement = receiver.Elements("Row").C ast(Of XElement)().Where(Function (n) n.Element("Receiver_ID").V alue = receiverId).FirstOrDefault ()
If xe IsNot Nothing Then
receiverVal = xe.Element("Receiver").Val ue
End If
Dim DonorVal As String = String.Empty
xe = Donor.Elements("Row").Cast (Of XElement)().Where(Function (n) n.Element("Donor_ID").Valu e = 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.WinFor ms.ReportP arameter() = New Microsoft.Reporting.WinFor ms.ReportP arameter(1 ) {}
Dim reportDataSource As New Microsoft.Reporting.WinFor ms.ReportD ataSource( )
reportDataSource.Name = "MyDataSet_Links"
reportDataSource.Value = dt
RptParameters(0) = New Microsoft.Reporting.WinFor ms.ReportP arameter(" TextboxCol or1", textcolor)
RptParameters(1) = New Microsoft.Reporting.WinFor ms.ReportP arameter(" TextboxCol or2", "LightGreen")
ReportViewer1.LocalReport. DataSource s.Add(repo rtDataSour ce)
ReportViewer1.LocalReport. SetParamet ers(RptPar ameters)
ReportViewer1.LocalReport. Refresh()
ReportViewer1.RefreshRepor t()
Thanks.
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.WinFor
RptParameters(1) = New Microsoft.Reporting.WinFor
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.
Dim receiver As XElement = XElement.Load(Application.
Dim Donor As XElement = XElement.Load(Application.
For Each item As XElement In linker.Elements("Row")
Dim linkID As String = item.Element("Link_ID").Va
Dim receiverId As String = item.Element("Receiver_ID"
Dim DonorID As String = item.Element("Donor_ID").V
Dim receiverVal As String = String.Empty
Dim xe As XElement = receiver.Elements("Row").C
If xe IsNot Nothing Then
receiverVal = xe.Element("Receiver").Val
End If
Dim DonorVal As String = String.Empty
xe = Donor.Elements("Row").Cast
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.WinFor
Dim reportDataSource As New Microsoft.Reporting.WinFor
reportDataSource.Name = "MyDataSet_Links"
reportDataSource.Value = dt
RptParameters(0) = New Microsoft.Reporting.WinFor
RptParameters(1) = New Microsoft.Reporting.WinFor
ReportViewer1.LocalReport.
ReportViewer1.LocalReport.
ReportViewer1.LocalReport.
ReportViewer1.RefreshRepor
Thanks.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Got it. Thank You very much.
{
txt1.BackColor = System.Drawing.Color.Red;
}