简体   繁体   中英

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

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.

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:

     <Columns>
        <asp:HyperLinkField
             HeaderText="Header text"
             DataNavigateUrlFields="PropertyContainingTheHRefForTheAnchor"
             DataTextField="PropertyContainingTheTextForTheAnchor"
             />
     </Columns>

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:

     <Columns>
       <asp:HyperLinkField
             HeaderText="Header text"
             DataNavigateUrlFields="PathProperty"
             DataTextField="TextProperty"
             />
     </Columns>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM