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">
  <ItemTemplate>
    <asp:Button ID="gvSelectButton" CommandName="Select" Text="Select" Runat="Server" />
  </ItemTemplate>
</asp:TemplateField>  

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

thanx
LVL 1
heincpaAsked:
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
0
 
pbocanegraCommented:
the button is a server controls and triggered events. Usually, the hyperlink is a pointer to another place.
0
 
heincpaAuthor Commented:
Awesome...

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

aspx page

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

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!
0
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.