How to create dynamic links from a database

Posted on 2008-11-04
Last Modified: 2013-12-17
I am able to pull a list of stories from a database, however, I want to pull a list of stories and link to the page that displays the story.  For example I want to list the story title and have the story title be a link that links to page that displays a story based on the story ID.  

I can display the list of stories, and I have a page that will display the story based on an ID, however, how to I create the link for the title?

<a href="story.aspx?ID='storyID'>Story Title</a>

That is what I am trying todo.  

Thank you for any advice.  I am using c# with SQL server back end.
Question by:shanemay
    LVL 7

    Expert Comment

    Well a real rudimental way is to have
    1. a Table (say tblStory with Columns StoryID, Title, Body)
    2. you have maye a stored procedure that takes a storyID as a parameter and retrieves the table row associated with the ID
    3. on the Story.aspx you have place holders to display the Title and the body.
    LVL 6

    Accepted Solution

    What i could do is use a repeater and bind to it an SqlDataSource that retrieves Story ID and Stroy Title.
    SqlDataSource would have a Select statemnt like "SELECT STORY_ID, STORY_NAME FROM STORY".

    <asp:Repeater ID="repParty" runat="server" DataSourceID="SqlDataSource1">
                     <a href="<%FormatUrl(DataBinder.Eval(Container.DataItem, "STORY_ID")) %>"><%#DataBinder.Eval(Container.DataItem, "STORY_NAME")%></a>

    And then in the code behind file put this function:
    public string FormatUrl(string id)
        string url = "story.aspx?ID=" + id;
        return url;

    Hope This Helps

    Author Closing Comment

    Thank you for the help, with a little bit of modification that worked excatly like I needed it to.  I really appericiate your help.  Thanks.

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Join & Write a Comment

    A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
    Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…

    734 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

    18 Experts available now in Live!

    Get 1:1 Help Now