HyperLinkField vs Button

Posted on 2006-03-28
Last Modified: 2012-08-14
How do I make

<asp:HyperLinkField Text="Select" DataNavigateUrlFields="nPDID"
  DataNavigateUrlFormatString="DetailsViewEdit.aspx?ID={0}" />    

look like

<asp:TemplateField ItemStyle-VerticalAlign="Top">
    <asp:Button ID="gvSelectButton" CommandName="Select" Text="Select" Runat="Server" />

or how to make a button that will call the same thing as the hyperlink field.

Question by:heincpa
    LVL 4

    Expert Comment

    the button is a server controls and triggered events. Usually, the hyperlink is a pointer to another place.
    LVL 22

    Accepted Solution

    Within your GridView's RowCommand event you can have code like the following:

    If e.CommandName = "Select" Then
      Response.Redirect("DetailsViewEdit.aspx?ID=" & CStr(e.CommandArgument))
    End If

    You'll have to set the CommandArgument field on your Button, something like:
    <asp:Button ID="gvSelectButton" CommandName="Select" CommandArgument='<%# Eval("nPDID") %>'Text="Select" Runat="Server" />

    Good luck!
    -- Jason
    LVL 1

    Author Comment


    and because I hate it when people just say thanx and don't post the final solution:

    aspx page

                            <asp:Button CommandName="Select" CommandArgument='<%# Eval("nPDID") %>' Text="Select" runat="server"/>

    code behind:

        protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
            if (e.CommandName == "Select")

                Response.Redirect("DetailsViewEdit.aspx?ID=" + e.CommandArgument.ToString());


    had to use tostring instead of CStr - VB vs C#

    Thanx a bunch!

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
    Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    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…

    755 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

    19 Experts available now in Live!

    Get 1:1 Help Now