Results 1 to 3 of 3

Thread: Adding "HTTP://" to URL's

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2005
    Location
    Lancashire UK
    Posts
    375

    Adding "HTTP://" to URL's

    Hi, I'm developing a website for a company that has all their client details on an access database, this information includes a web address which is stored as "www.somebody.com".
    The problem is when I use a hyperlink column in the datagrid and bind this field to it, the URL appears as "http://customers_site/www.somebody.com" instead of http://www.somebody.com. I thought it would be simple to add "http://" to the begining of the address using the following code:

    Code:
    <asp:Hyperlink NavigateURL="http://" & '<%# Container.DataItem("website")%>' Text="Website" runat="server" />
    But this doesn't work, I'm pretty new to asp.net so any help would be appreciated, the only other optionj is to manually add http:// to every entry in the database which I want to avoid if possible

  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Adding "HTTP://" to URL's

    Let the hyperlink look like:

    <asp:Hyperlink id="hylEdit" Text="Website" runat="server" />

    In the datagrid's ItemDataBound event, do this:

    VB Code:
    1. If e.Item.ItemType = ListItemType.AlternatingItem Or e.Item.ItemType = ListItemType.Item Then
    2.  
    3.             Dim hylD As New HyperLink
    4.             hylD = CType(e.Item.FindControl("hylEdit"), HyperLink)
    5.             hylD.NavigateUrl = "http://" & ds.Tables(0).Rows(e.Item.ItemIndex).Item("website").ToString()
    6.  
    7.         End If

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2005
    Location
    Lancashire UK
    Posts
    375

    Re: Adding "HTTP://" to URL's

    Thanks for the reply, I'm having trouble getting it to work though

    I'm not using a dataset in the site, just binding the data direct to the datagrid using the datasource, databind methods.

    Would I be better off using a datagrid ? and do I have to use a datagrid to add the http:// ?

    Sorry if these are daft question, but I'm still very green

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width