Solved

Need help with HyperLink

Posted on 2004-09-04
10
730 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

A basic question.. “What is the Garbage Collector?” The usual answer given back: “Garbage collector is a background thread run by the CLR for freeing up the memory space used by the objects which are no longer used by the program.” I wondered …
In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

739 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