Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hyperlink Field Problem

Status
Not open for further replies.

BBousman

Programmer
May 10, 2004
57
US
What I'm trying to do is make that Hyperlink field show the value of Barcode as the Text and then the hyperlink will be the value of EmailLink based off the values in the SQL Server.

Whenever I set
DataNavigateUrlFields = "EmailLink"
and
DataNavigateUrlFormatString = "{0}"
it won't give me the option to do a hyperlink.

When I change the ...UrlFields = "ScanID" then it will link but obviously that's not what I want.

The EmailLink field is an NVARCHAR(200) so does that have anything to do with it?

A common value for this field is this:
file:\\10.2.1.65\Archive\4-2-2008_11-36-21_AM_V01013317771_TPN_SUR.tif

Here's my whole code:
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:pSCRIPTConnectionString %>"
SelectCommand="SELECT [Barcode], [PatientFullName], [Type], [PatientUnitNumber], [ScanDateAndTime], [ScanID], [EmailLink] FROM [SCANS]">
</asp:SqlDataSource>
<asp:GridView ID="GridView1" runat="server" AllowSorting="True"
AutoGenerateColumns="False" DataKeyNames="ScanID"
DataSourceID="SqlDataSource1" Height="115px" Width="495px">
<Columns>
<asp:HyperLinkField DataTextField="Barcode" HeaderText="Account Number" SortExpression="Barcode"
DataNavigateUrlFields="EmailLink" DataNavigateUrlFormatString="{0}" />

<asp:BoundField DataField="PatientFullName" HeaderText="Patient Name"
SortExpression="PatientFullName" />
<asp:BoundField DataField="PatientUnitNumber" HeaderText="Unit Number"
SortExpression="PatientUnitNumber" />
<asp:BoundField DataField="Type" HeaderText="Order Type"
SortExpression="Type" />
<asp:BoundField DataField="ScanDateAndTime" HeaderText="Scan Time"
SortExpression="ScanDateAndTime" />
</Columns>
</asp:GridView>
 
Normally when you have a hyperlink, it's underlined and when you hover over it, it will change the pointer to a hand and show you the link in the status bar.

I.E.
However, when I do it, it just looks like normal text

I.E. V1234567890
 
Yeah it hasn't been rendered as a hyperlink, it just stays as normal text unless I change it to ScanID which is an INT in the SQL DB so I don't know if that has anything to do with it.

The code that I have above is pretty much everything I have right now, I have an image at top but that's it. There's no other HTML being sent to the browser.
 
You will need to look at View Source in your browser to see what HTML was sent. The above is just the code that ASP.NET uses to create the necessary HTML.


-------------------------------------------------------

Mark,
[URL unfurl="true"]http://aspnetlibrary.com[/url]
[URL unfurl="true"]http://mdssolutions.co.uk[/url] - Delivering professional ASP.NET solutions
[URL unfurl="true"]http://weblogs.asp.net/marksmith[/url]
 
Here's what it shows for my table that's created:

<a>V01013317771</a>
<a>V01013484679</a>

It's not putting the href part of the tag in there for some reason.
 
It could be to do with the backslashes if "
file:\\10.2.1.65\Archive\4-2-2008_11-36-21_AM_V01013317771_TPN_SUR.tif" is the full value of the field in the database (or is the full value "V01013317771" and you are trying to append the rest?).

Either way, I'd use a TemplateField, put a HyperLink of a HTML anchor with runat="server" in there and set the NavigateURL from your code - that way it will be much easier for you to debug and you can see exactly what value is getting assigned to where.


-------------------------------------------------------

Mark,
[URL unfurl="true"]http://aspnetlibrary.com[/url]
[URL unfurl="true"]http://mdssolutions.co.uk[/url] - Delivering professional ASP.NET solutions
[URL unfurl="true"]http://weblogs.asp.net/marksmith[/url]
 
I think it does have something to do with the slashes. I can put pretty much whatever field I want to in there and it will work but once I put that field or another one that contains "C:\..." then it doesn't work.
 
That's because you aren't putting the URL information in the property...

here is an example of how format it:

Code:
<asp:HyperLinkField DataTextField="au_lname" 
	DataNavigateUrlFields="au_ID" 
	DataNavigateUrlFormatString="NewPage.aspx?id={0}"
	HeaderText="Click For Details" />
 
Yeah I tried that too and it still does the same thing:

<asp:HyperLinkField DataNavigateUrlFields="EmailLink"
DataNavigateUrlFormatString="Default.aspx?id={0}" DataTextField="Barcode"
HeaderText="Account Number" SortExpression="Barcode" />
 
I would go about this a different way.
create a hyperlink which passes the id (not the file) in the url.
then on the handler, get the id, query the database for the file name and load the file to the response stream.
Code:
<asp:HyperLinkField 
    DataNavigateUrlFields="id" 
    DataNavigateUrlFormatString="ViewFile.as[COLOR=red]h[/color]x?id={0}"
    HeaderText="View File" />
note it's a web handler, not a webform.
Code:
public class ViewFile : IHttpHandler
{
   public bool IsReusable { get {return true; } }

   public void Process(HttpContext context)
   {
       int id = int.Parse(Request.QueryString["id"]);
       string file = GetFileNameFromSomeWhere(id);
       Response.Write(new FileStream(file));
   }
}
you may need to set the Response headers as well.
with this method you protect your files from being displayed in the address bar. you can also now add security/logging to the handler if this becomes a requirement.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top