HyperLinkField vs Button

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.

Who is Participating?
Jason ScolaroCommented:
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
the button is a server controls and triggered events. Usually, the hyperlink is a pointer to another place.
heincpaAuthor Commented:

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!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.