Adding Hyperlink in DataGrid Control

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • globalguideline
    New Member
    • Jan 2008
    • 3

    Adding Hyperlink in DataGrid Control

    Hi!

    I am using a DataGrid to show my table values. Some of the columns are showing
    integer data. I need to show these IDs (Integer values) data as hyperlinks so that the
    user can drill downward or get more details about the data. How to do this pleas if any one
    knows gude me thanks a lot in advance.
    Ali.
  • enggwaqas
    New Member
    • Jun 2007
    • 19

    #2
    Originally posted by globalguideline
    Hi!

    I am using a DataGrid to show my table values. Some of the columns are showing
    integer data. I need to show these IDs (Integer values) data as hyperlinks so that the
    user can drill downward or get more details about the data. How to do this pleas if any one
    knows gude me thanks a lot in advance.
    Ali.
    There are two ways of doing this:

    1. Using HyperLinkColumn colum, e.g:
    Code:
    <asp:DataGrid ID="dg" runat="server">
                <Columns>
                    <asp:HyperLinkColumn DataNavigateUrlFormatString="~/more.aspx?id={0}" DataNavigateUrlField="id" DataTextField="name" />
                </Columns>
            </asp:DataGrid>
    2. Using ItemTemplate and <a> tags

    Code:
    <asp:DataGrid ID="dg" runat="server">
                <Columns>                
                    <asp:TemplateColumn>
                        <ItemTemplate>
                            <a href="more.aspx?id=<%#Eval("id") %>"><%#Eval("Name") %></a>
                        </ItemTemplate>
                    </asp:TemplateColumn>
                </Columns>            
            </asp:DataGrid>
    In the above code "id" and "name" are the column names. Value in name column will be displayed with a hyperlink to more.aspx page with the value of id column in query string.

    Comment

    Working...