IF you have set
DataKeyNames
or
DataMember
And you have a OnRowCommand event added to your gridview, then in your gridview OnCommand eventhandler you can:
- check the Row of GridView that was clicked
- Set the GridView.SeletedValue in Session or Viewstate
-Redirect to the other page
- Find in Session or ViewState the SelectedValue and set this value as sqlparameter
to run with your stored procedure.
- Set the result in a dataset/datatable object and do with it what you need.
Example:
In ASPX I have a ImageButton Control in the row
<pre lang="xml"><asp:TemplateField ItemStyle-Width="60px">
<EditItemTemplate>
<asp:ImageButton runat="server" ID="imgCancel" CssClass="GridPlaatje" ImageUrl="~/Images/NewDesign/ImageCancel16x16.png" CommandName="CancelItem" AlternateText="Cancel" OnCommand="Grid_OnCommand"/><asp:ImageButton runat="server" ID="imgSafe" CssClass="GridPlaatje" ImageUrl="~/Images/NewDesign/Accept16x16.png" CommandName="SafeItem" AlternateText="Save" OnCommand="Grid_OnCommand" />
</EditItemTemplate>
<ItemTemplate>
<asp:ImageButton runat="server" ID="imgEdit" CssClass="GridPlaatje" ImageUrl="~/Images/NewDesign/pencil.png" CommandName="EditGrid" AlternateText="Edit" OnCommand="Grid_OnCommand" />
</ItemTemplate>
</asp:TemplateField>
The GridOnCommand EventHandler is stated in this part.
In the CodeBehind you can find your selected row with the next code:
<pre lang="C++">protected void Grid_OnCommand(Object sender, CommandEventArgs e)
{
lblError.Text = String.Empty;
ImageButton btn = (ImageButton)sender;
GridViewRow row = (GridViewRow)btn.NamingContainer;
String value = row.RowIndex;
Session["MyDetailValue"] = value;
Response.Redirect("someOtherPage.aspx");
}