Solved

Need help with HyperLink

Posted on 2004-09-04
10
718 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
 

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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
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 …
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

746 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now