Solved

Need help with HyperLink

Posted on 2004-09-04
10
726 Views
Last Modified: 2008-01-09
I need some help with my asp .net page. I have an Access DB with 2 fields, one is the name, and the other is the link, and I would like to get the Name to display on the page and the link from the DB to be the Hyperlink.
I'm posting my code, because I getting somethink wrong. I can get everything that I need but when I check the link on the page I get the full link from my site, and after the link that I want.
EX.

http://www.ebdizin.com/#http://www.leathercoatsetc.com#
and I just need
http://www.leathercoatsetc.com

here is the code
[code]
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>
<!-- DataBase Connection -->

<script runat="server">
   Sub Page_Load(s As Object, e As EventArgs)
      Dim myConnection As OleDbConnection
      Dim myCommand As OleDbCommand
       
       myConnection = New OleDbConnection( "PROVIDER=Microsoft.Jet.OLEDB.4.0; DATA Source=c:\sites\Single1\ebozzetti\database\ebdizin.mdb")
      myCommand = New OleDbCommand ( "Select Name, Link From portfolio", myConnection)
       myConnection.Open()
       myRepeater.DataSource = myCommand.ExecuteReader()
       myRepeater.DataBind()
       myConnection.Close()
   End Sub
</script>
.
.
.
    <form runat="server">
     <asp:Repeater id="myRepeater" runat="server">
     <itemtemplate>
     <asp:HyperLink ID="myLink" Text='<%# Container.DataItem("Name") %>' NavigateUrl='<%# Container.DataItem("Link") %>'  Target="_blank" runat="server"></asp:HyperLink><br>
     </itemtemplate>
     </asp:Repeater>
     
     </form>
[/code]
0
Comment
Question by:Enniobozzetti
  • 5
  • 5
10 Comments
 
LVL 3

Accepted Solution

by:
nhewitt21 earned 50 total points
ID: 11988825
try replacing:
<asp:HyperLink ID="myLink" Text='<%# Container.DataItem("Name") %>' NavigateUrl='<%# Container.DataItem("Link") %>'  Target="_blank" runat="server"></asp:HyperLink><br>

with:
<asp:Label id="myLink" text='<%#"<a target=\"_blank\" href=\"" + (DataBinder.Eval(Container.DataItem,"Link").ToString()) + "\">" + (DataBinder.Eval(Container.DataItem,"Name").ToString()) + "</a>"%>' runat="server" />

thats how i've done similar stuff.
Hope it helps.
0
 

Author Comment

by:Enniobozzetti
ID: 11997578
I'm getting an Error with this solution

BC30516: Overload resolution failed because no accessible 'ToString' accepts this number of arguments
0
 
LVL 3

Expert Comment

by:nhewitt21
ID: 11997795
when you accepted my answer was it working or did you accept it before checking it worked?

hmm, try taking out the .ToString() bits.
If thats doesn't work can you send me the .aspx so i can look?
0
How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

 

Author Comment

by:Enniobozzetti
ID: 11998851
Sorry I accepted before checking the code....
I removed the toString()... and I still get the same error.
Here is my code.


[code]
<%@ Page Language="VB" ContentType="text/html" ResponseEncoding="iso-8859-1" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>
<!-- DataBase Connection -->

<script runat="server">
   Sub Page_Load(s As Object, e As EventArgs)
      Dim myConnection As OleDbConnection
      Dim myCommand As OleDbCommand
        
        myConnection = New OleDbConnection( "PROVIDER=Microsoft.Jet.OLEDB.4.0; DATA Source=c:\sites\Single1\ebozzetti\database\ebdizin.mdb")
      myCommand = New OleDbCommand ( "Select Name, Link From portfolio", myConnection)
        myConnection.Open()
        myRepeater.DataSource = myCommand.ExecuteReader()
        myRepeater.DataBind()
        myConnection.Close()
   End Sub

   Function GetURL (ByVal fldval As String) As String
      If InStr(fldval, "http://")Then
      Return fldval
      Else
      Return "http://" & fldval
      End If
   End Function

</script>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>EBDIZIN.COM</title>
<style type="text/css">
<!--
body {
      background-color: #CCCCCC;
}
body,td,th {
      font-family: Arial, Helvetica, sans-serif;
      font-size: 14px;
      color: #000000;
      font-weight: bold;
      border-color: #000000;
      border-left-color: #000000;
      border-right-color: #000000;
      border-top-color: #000000;
      border-width: 1;
}
.style1 {font-size: 12px}
a {
      font-size: 12px;
      color: #000000;
}
a:link {
      text-decoration: none;
}
a:visited {
      text-decoration: none;
      color: #333333;
}
a:hover {
      text-decoration: none;
}
a:active {
      text-decoration: none;
}
.style2 {
      font-size: 10px;
      color: #FF0000;
}
.style3 {
      font-size: 12px;
      color: #000000;
}
-->
</style></head>
<body>

<table width="955" border="0" cellpadding="0" cellspacing="0">
  <!--DWLayoutTable-->
  <tr>
    <td width="184" height="63">&nbsp;</td>
    <td colspan="3" valign="top"><div align="center">
      <p>&nbsp;</p>
    </div></td>
    <td width="184">&nbsp;</td>
  </tr>
  <tr>
    <td height="136">&nbsp;</td>
    <td colspan="3" valign="top"><p><img src="Images/menu.jpg" alt="" width="587" height="136" border="0"><span class="style1">
    </span></p></td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td height="301">&nbsp;</td>
    <td width="23">&nbsp;</td>
    <td width="177" valign="top"><br>
2004 Portfolio:<br>
    <form runat="server">
      <asp:Repeater id="myRepeater" runat="server">
      <itemtemplate>
         <asp:Label id="myLink" text='<%#"<a target=\"_blank\" href=\"" + (DataBinder.Eval(Container.DataItem,"Link")) + "\">" + (DataBinder.Eval(Container.DataItem,"Name")) + "</a>"%>' runat="server" />

      </itemtemplate>
      </asp:Repeater>      
      </form>
        </td>
    <td width="387">&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
</table>
</body>
</html>
[/code]
0
 

Author Comment

by:Enniobozzetti
ID: 11998855
ignore the function on top (GETURL) that was a test
0
 
LVL 3

Expert Comment

by:nhewitt21
ID: 11998943
ok try replacing this:
<asp:Label id="myLink" text='<%#"<a target=\"_blank\" href=\"" + (DataBinder.Eval(Container.DataItem,"Link")) + "\">" + (DataBinder.Eval(Container.DataItem,"Name")) + "</a>"%>' runat="server" />

with this:
<asp:Label id="myLink" text='<%#"<a href=\"" + Container.DataItem("Link") + "\" target=\"_blank\">" + Container.DataItem("Name") + "</a>"%>' runat="server" />
0
 

Author Comment

by:Enniobozzetti
ID: 11999818
ok that works but I still get error on the hyperlink...
if you go to the web site you can take a look on how it's wrong..

go to

http://www.ebdizin.com/default2.aspx
0
 
LVL 3

Expert Comment

by:nhewitt21
ID: 12000648
ok for some reason its putting a # infront of your href and after it.

If you view source it shows the links like this:
<a href=#http://www.leathercoatsetc.com#>Leather Coats Etc</a>

i just noticed its missing the target="_blank" too.

try this:
<asp:Label id="myLink" text='<%#"<a href=" + Container.DataItem("Link") + " target=_blank>" + Container.DataItem("Name") + "</a>"%>' runat="server" />
0
 

Author Comment

by:Enniobozzetti
ID: 12041091
it worked thank you...
I had to fix my DB...
0
 
LVL 3

Expert Comment

by:nhewitt21
ID: 12041698
NP, glad its working :)
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

IP addresses can be stored in a database in any of several ways.  These ways may vary based on the volume of the data.  I was dealing with quite a large amount of data for user authentication purpose, and needed a way to minimize the storage.   …
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

830 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