We help IT Professionals succeed at work.

HyperLinkField vs Button

heincpa asked
Medium Priority
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.

Watch Question

the button is a server controls and triggered events. Usually, the hyperlink is a pointer to another place.
Top Expert 2006
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

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts



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!
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.