You can use the
PostbackUrl
property of the button and set it to the page you want to post. Now at your current page expose the
selected row as a public property
.
Declare the previous page type
in in your other page like
<%@ PreviousPageType VirtualPath="~/Default.aspx" %>
. All set. Now you can access the public property in your page 1 to page 2 by use the object
PreviousPage
which is actually an instance of your page1 and accessible in page2.
Good luck
For example at the grid view mark up or in the code behind define handlers for
RowBound and RowCommand
events
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataKeyNames="ProductId" DataSourceID="SqlDataSource1"
OnRowCommand="GV_RowCommand" OnRowDataBound="GV_RowBound"
>
Have template field with button, set its
CommandName and PostBackUrl
<asp:TemplateField>
<ItemTemplate>
<asp:Button CommandName="Redirect" ID="Redirect" runat="server" PostBackUrl="~/Default2.aspx" Text="Redirect" />
</ItemTemplate>
</asp:TemplateField>
At the event handlers in code behind..
public GridViewRow SelectedRow { get; set; }
protected void GV_RowBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
Button btn = e.Row.FindControl("Redirect") as Button;
btn.CommandArgument = e.Row.RowIndex.ToString();
}
}
protected void GV_RowCommand(object sender, GridViewCommandEventArgs e)
{
GridViewRow row = GridView1.Rows[Convert.ToInt32(e.CommandArgument)];
SelectedRow = row;
}
At page 2 define the previous page type
<%@ PreviousPageType VirtualPath="~/Default.aspx" %>
Then from the code behind of the page2...
protected void Page_Load(object sender, EventArgs e)
{
GridViewRow row = this.PreviousPage.SelectedRow;
}