Search code examples
asp.nethref

ASPNET : Use the label inside the link with database


I have a link like this: <a href ="xxx/category.html">

How can I add from xxx with database?

I have tried like this:

<a href="<asp:Label ID="lblCatAdSeo" runat="server" Text=""></asp:Label>/<%#Eval("Category")%>.html">

Solution

  • One solution might be defining a code-behind method for this:

    <a href='<%# GetFullUrl((string)Eval("Category")) %>'>
    

    And in code-behind define it like this:

    protected string GetFullUrl(string categoryName)
    {
        // derive the full url
        return url;
    }
    

    If you are getting relevant url parts elsewhere, say during the Page_Load, you can simply store this info in some private field, and use it lately in this method.