turn sql rows into links on a vb.net page?

Go To StackoverFlow.com


I am trying to create a specific aspx page where I display clickable links based on information in a sql database. For example one column could be the anchor tag another column could be the path to the link itself etc. In the past I would pull this information from sql and put it into a non-visible Label (say linkLabel1). Then in the page itself I would insert <%linkLabel1.text%> to insert the link path from the database to the appropriate area.

I hope I'm not confusing things too much here and that makes sense how I explained it.

What I would like to do is set up a way that I could simply enter a new row into a SQL table with link information and a web page automatically displays the new link for me.

I guess I am mostly looking for insight, opinions, or directions of what approach to consider. I can elaborate if I was unclear (wouldn't be awfully surprising if I was not).

Thanks in advance for anyone's time on this matter.

2012-04-04 19:54
by BradtotheBone


Since you are displaying this in a table, you could use a GridView for this. The columns that will display the link could be defined as hyperlink columns as so:

             HeaderText="Header text"

So for example, if you return a record set containing these columns:

TextProperty             PathProperty
See Details              Assets/SomeOther/
Click me                 Products/AnotherPath/

Your grid will render these as:

<a href="Assets/SomeOther/">See Details</a>
<a href="Products/AnotherPath/">Click me</a>

If you define the column as:

             HeaderText="Header text"
2012-04-04 20:00
by Icarus
Thanks for the advice, I didn't realize gridview had that possibility. Is this in the properties or can I only enter it into the code like your above example - BradtotheBone 2012-04-04 20:05
If you click on the arrow next to the grid in the designer and click on edit columns you can add this column without pasting in the Tag - JonAlb 2012-04-04 20:11
@BradtotheBone I Am not sure I understand your question... You can declare this either from the markup (as I showed on my example) or you can access this programmatically - Icarus 2012-04-04 20:11
Thanks I'll take a run at it and hope for the best. I'm still a beginner as you can see and I'm self-taught so I'm not very fluent in the jargon quite yet. I appreciate the help very much though and I'll let you know how it goes. Thanks again - BradtotheBone 2012-04-04 20:16
Well that was stunningly easy. Thanks again for the help, it worked like a charm and you are my new hero - BradtotheBone 2012-04-04 20:32