?
Solved

Need help with HyperLink

Posted on 2004-09-04
10
Medium Priority
?
736 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 200 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
CHALLENGE LAB: Troubleshooting Connectivity Issues

Goal: Fix the connectivity issue in the lab's AWS environment so that you can SSH into the provided EC2 instance.  

 

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 Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

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

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

765 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