Monday, January 19, 2009

Adding dynamic hyperlinks in the Report Viewer; ASP.Net Reports

Adding dynamic hyperlinks in the Report Viewer; ASP.Net Reports

Type the text to be displayed as the Hyperlink in the cell of your Table control added in the RDLC file. Right click on the Hyperlink text cell and click 'Navigation' tab.

Click Jump to URL radio button and add expression by clicking 'fx' button.

=iif(1<>0, Parameters!MyLink.Value+"?qBTchId=" & Fields!BatchID.Value, "")
Report Parameters can be sent from the code behind file as

Microsoft.Reporting.WebForms.ReportParameter RptLink1 = new Microsoft.Reporting.WebForms.ReportParameter("AssignLink", UriBuilder.BuildUrlNew(@"../Training/FrmAssignTraining.aspx"));
Microsoft.Reporting.WebForms.ReportParameter RptLink2 = new Microsoft.Reporting.WebForms.ReportParameter("UpdateLink", UriBuilder.BuildUrlNew(@"../Training/FrmTrainingUpdate.aspx"));
Microsoft.Reporting.WebForms.ReportParameter RptLink3 = new Microsoft.Reporting.WebForms.ReportParameter("PrintLink", UriBuilder.BuildUrlNew(@"../Training/FrmTrainingPrint.aspx"));

RptTraining.LocalReport.SetParameters(new Microsoft.Reporting.WebForms.ReportParameter[] { RptLink1, RptLink2, RptLink3 });

RptTraining.LocalReport.EnableHyperlinks = true;


=iif(1<>0,Fields!Status.Value, "")
******************/
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

///
/// The common class for building the URL for the report. Eg: UriBuilder.BuilUri("FrmAdvance.aspx");
///
public class UriBuilder
{
public UriBuilder()
{
//
// TODO: Add constructor logic here
//
}
///
/// This method Builds the physical Url with the page name provided
///
/// The name of the page
/// The URL string
public static string BuildUrl(string pageName)
{
Uri uri = new Uri(HttpContext.Current.Request.Url.AbsoluteUri);
Uri newUri = new Uri(uri, pageName);
return newUri.AbsoluteUri;
}

public static string BuildUrlNew(string pageName)
{
Uri uri = new Uri(HttpContext.Current.Request.Url.AbsoluteUri.Replace("/FeedBackQuality", ""));
Uri uri2 = new Uri(
Uri newUri = new Uri(uri, pageName);
return newUri.AbsoluteUri;
}
}


Report viewer; changing the cell background color dynamically

Report viewer; how to change the cell background color dynamically?

Select the cell which has to be colored, and press 'f4' key to get the 'properties' window of Visual Studio IDE. Go to 'BackgroundColor' property and click the '' under the dropdown list.

Just give a condition for your entity property.
=iif(Fields!TotalPrice.Value = "2500", "DarkGray", "")