Solved

Need help with HyperLink

Posted on 2004-09-04
10
733 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
Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

 

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

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

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

The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

724 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