I hope the below example will help you. This is an abstract from one of my projects which do the same thing as you need.
As an outline, you have to perform the following steps:
- In the GridView, create a TemplateField which contain the link to navigate to other page (linkButton or imageButton or Button)
- Set CommandArgument and CommandName properties for that link control
- In your C# code, handle gridView's RowCommand event
- Based on the commandName and commandArgument navigate to the other page.
.ASPX
<asp:GridView ID="gv" runat="server" AutoGenerateColumns="False" OnRowCommand="gv_RowCommand"
EmptyDataText="No record found" Width="1000px">
<Columns>
<asp:BoundField DataField="ISBN" />
<asp:BoundField DataField="Title" HeaderText="Title"/>
.
.
.
.
.
<asp:TemplateField HeaderText="Actions">
<ItemTemplate>
<asp:LinkButton ID="lnkEdit" runat="server" CommandArgument='<%# Eval("ISBN") %>'
CommandName="viewDetails">View Details</asp:LinkButton> </ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
In the above code, the main thinks to see are setting CommandArgument and CommandName properties of the LinkButton. These will be used in the .cs code
.ASPX.CS
protected void gv_RowCommand(object sender, GridViewCommandEventArgs e)
{
// ensure that commandArgument is not null, which may happen when someone tries to hack the page
string isbn = e.CommandArgument.ToString();
if (string.IsNullOrEmpty(uid))
{
// error message, someone has tried to hack the web page
return;
}
if (e.CommandName == "viewDetails")
{
Response.Redirect("book-details.aspx?isbn=" + isbn);
return;
}
// handle any other command that may be there (like delete, edit, etc)
}