Solved

Need Help with Visual Web Developer Gridview Hyperlink problem

Posted on 2008-10-25
12
656 Views
Last Modified: 2012-05-05
I am a beginner and I am using Visual Web Developer to create a website. In it, I have an Access DB in which I have a column of URLs for websites. I am using a GridView to show the data from the DB that comes from the AccessDataSource connecting to the DB. The GridView column is a hyperlink column and it lists the URLs as hyperlinks but when I click on them, it looks for them as is they are a page in the current project that I am creating( like http://www.mysite.com/www.cnn.com)   All of the websites are external websites, like www.cnn.com.

How do I set up the GridView to have the hyperlinks take me to the external sites?

Thanks for your help with this!!

0
Comment
Question by:mking777
  • 7
  • 5
12 Comments
 
LVL 13

Expert Comment

by:sm394
ID: 22804624
add link like that

<a href='<%# DataBinder.Eval(Container.DataItem, "link")%>' target="_blank">
                        <%# DataBinder.Eval(Container.DataItem, "title")%></a>
0
 

Author Comment

by:mking777
ID: 22804649
Where/how whould I put that in this section?
            <asp:GridView ID="GridView1" runat="server" AllowPaging="True" AutoGenerateColumns="False" DataSourceID="AccessDataSource1" Width="261px" PageSize="7">
                <Columns>
                    <asp:HyperLinkField DataTextField="URL" DataNavigateUrlFields="URL" HeaderText="BANKRUPTCY" />
                </Columns>
            </asp:GridView>
            <br />

Open in new window

0
 
LVL 13

Expert Comment

by:sm394
ID: 22804740
<Columns>
                <asp:TemplateField HeaderText="BANKRUPTCY">
                    <ItemTemplate>
                    <%#Container.DataItem %>
                   <a href='<%# DataBinder.Eval(Container.DataItem, "URL")%>' target="_blank">
                        <%# DataBinder.Eval(Container.DataItem, "URL")%></a>
                    </ItemTemplate>
                </asp:TemplateField>
             
            </Columns>
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 

Author Comment

by:mking777
ID: 22804811
Thanks but all it now shows is "System.Data.DataRowView " in the GridView. Any suggestions?
0
 
LVL 13

Expert Comment

by:sm394
ID: 22804921
Are Your urls starting with http://

or just www
0
 

Author Comment

by:mking777
ID: 22804929
Just www. Should I change it to also have http:// ?
0
 
LVL 13

Expert Comment

by:sm394
ID: 22804945
yes change to http://www.bbc.co.uk something like that
you can change in your table or you can try below i have embeded http:// in code
  <ItemTemplate>
                        <a href= <%# "http://"+ Eval( "ProductName")%> target="_blank">
                            <%# DataBinder.Eval(Container.DataItem, "ProductName")%></a>
                    </ItemTemplate>
0
 
LVL 13

Assisted Solution

by:sm394
sm394 earned 500 total points
ID: 22804952
if you change urls in your table from www to http://www 
then change this section <%# "http://"+ Eval( "ProductName")%>
to <%#  Eval( "URL")%>

 <ItemTemplate>
                        <a href= <%# Eval( "URL")%> target="_blank">
                            <%# DataBinder.Eval(Container.DataItem, "URL")%></a>
                    </ItemTemplate>
0
 

Accepted Solution

by:
mking777 earned 0 total points
ID: 22804960
Ok, I changed the data and it now does link the data to the correct site but still shows  "System.Data.DataRowView " in the GridView too. What do I do? Again, I appreciate your help.
0
 
LVL 13

Expert Comment

by:sm394
ID: 22804989
could you please post your code
0
 

Author Comment

by:mking777
ID: 22804999
Your solution worked. THANKS. I AWARDED YOU THE POINTS!!!
0
 
LVL 13

Expert Comment

by:sm394
ID: 22805029
Thanks but you should have accepted the solution by hiting Green Solution Accepted button  not by closing the question.
anyway glad your problem is resolved
Happy Coding :)
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

I've been asked to discuss some of the UX activities that I'm using with my team. Here I will share some details about how we approach UX projects.
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
This video teaches viewers how to create their own website using cPanel and Wordpress. Tutorial walks users through how to set up their own domain name from tools like Domain Registrar, Hosting Account, and Wordpress. More specifically, the order in…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

803 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