Using
$("a").attr("href", "http://www.google.com/")
will modify the href of all hyperlinks to point to Google. You probably want a somewhat more refined selector though. For instance, if you have a mix of link source (hyperlink) and link target (a.k.a. "anchor") anchor tags:
<a name="MyLinks"></a>
<a href="http://www.codeproject.com/">The CodeProject</a>
...Then you probably don't want to accidentally add href
attributes to them. For safety then, we can specify that our selector will only match <a>
tags with an existing href
attribute:
$("a[href]") //...
Of course, you'll probably have something more interesting in mind. If you want to match an anchor with a specific existing href
, you might use something like this:
$("a[href='http://www.google.com/']").attr('href', 'http://www.live.com/')
This will find links where the href
exactly matches the string http://www.google.com/
. A more involved task might be matching, then updating only part of the href
:
$("a[href^='http://stackoverflow.com']")
.each(function()
{
this.href = this.href.replace(/^http:\/\/beta\.stackoverflow\.com/,
"http://stackoverflow.com");
});
The first part selects only links where the href starts with http://stackoverflow.com
. Then, a function is defined that uses a simple regular expression to replace this part of the URL with a new one. Note the flexibility this gives you - any sort of modification to the link could be done here.
A few things:
- You need to do this in code behind in my experience.
- You want a 'ReportViewer' object.
- I believe if you are hosting you need a reference to 'Microsoft.ReportViewer.WinForms' dll.
The code I used was done with xaml for WPF hosting a ReportViewer (abridged):
< Window x:Class="WPFTester.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:rv="clr-namespace:Microsoft.Reporting.WinForms;assembly=Microsoft.ReportViewer.WinForms"
>
......
<WindowsFormsHost Grid.Row="2">
<rv:ReportViewer x:Name="reportViewer"></rv:ReportViewer>
</WindowsFormsHost>
......
</Window>
The important part you get is that I have a 'ReportViewer' Object named 'reportViewer' for my code behind. ASP.NET has some equivalent of this object but you also will also need the dll in the alias of 'rv' or similar. The code works similar to this:
private void ResetReportViewer(ProcessingMode mode)
{
this.reportViewer.Clear();
this.reportViewer.LocalReport.DataSources.Clear();
this.reportViewer.ProcessingMode = mode;
}
private void ReportViewerRemoteWithCred_Load(object sender, EventArgs e)
{
ResetReportViewer(ProcessingMode.Remote);
reportViewer.ServerReport.ReportServerUrl = new Uri(@"(http://myservername/ReportServer");
reportViewer.ServerReport.ReportPath = "/Test/ComboTest";
DataSourceCredentials dsCrendtials = new DataSourceCredentials();
dsCrendtials.Name = "DataSource1"; // default is this you may have different name
dsCrendtials.UserId = "MyUser"; // Set this to be a textbox
dsCrendtials.Password = "MyPassword"; // Set this to be a textbox
reportViewer.ServerReport.SetDataSourceCredentials(new DataSourceCredentials[] { dsCrendtials });
reportViewer.RefreshReport();
}
Best Answer
Two approaches, the first assumes data is pre-formatted as a URL (e.g.
https://www.google.com
). The second assumes the URL is contained within some other text (e.g. 'This is a link to Google').URL Only
Right-click the field in design view, select
Text Box Properties
.Select the
Action
pane, select theGo to URL
radio button.In the
Select URL
textbox, enter the field value expression.URL Embedded in Text
Double-click the field in design view, then right-click
Create Placeholder
.In the
Value
textbox, enter the field value expression containing HTML tags.Under
Markup Type
, check theHTML - Interpret tags as styles
radio button.Verify link is displayed when report is run.