KoffeeKoder


  • Sometimes we need to get some id from the database table and use that id to generate the link. Something like this:
    SomePage.aspx?id=34
    You can easily do this by using the following code:

    <ItemTemplate>
    <asp:HyperLink ID="myHyperlink"
     Text='<%# Eval("CategoryName") %>'
     NavigateUrl='<%# FormatUrl( (int) Eval("CategoryID")) %>'
     runat="server">[myHyperlink]</asp:HyperLink>
           </ItemTemplate>

    And here is the FormatUrl method:

     protected string FormatUrl(int categoryID)
        {
            return "SomePage.aspx?" + categoryID;
        }

    This will create links inside the DataList control. You can try similar approach using Datagrid or GridView controls.