I’ve been stuck on this for hours, first time post. I Don’t know how to grab the value and postback to a new page with the selected row. I’ll be displaying the information in new page on it’s own (a detailed view if you will)
<asp:GridView ID="GameSearchGrid" runat="server"
AllowPaging = "True" AllowSorting = "True"
DataSourceID="EntityDataSource1" Width="502px" AutoGenerateColumns="False" >
<Columns>
<asp:CommandField ShowSelectButton="True" />
<asp:BoundField DataField="SKU" HeaderText="SKU" ReadOnly="True"
SortExpression="SKU" Visible="false" />
<asp:BoundField DataField="Name" HeaderText="Name" ReadOnly="True"
SortExpression="Name" />
<asp:BoundField DataField="GSystem" HeaderText="GSystem" ReadOnly="True"
SortExpression="GSystem" />
<asp:BoundField DataField="Rating" HeaderText="Rating" ReadOnly="True"
SortExpression="Rating" />
<asp:ButtonField ButtonType="Button" HeaderText = "select" Text="Select"
/>
</Columns>
</asp:GridView>
<asp:EntityDataSource ID="EntityDataSource1" runat="server"
ConnectionString="name=GameExpressEntities"
DefaultContainerName="GameExpressEntities" EnableFlattening="False"
EntitySetName="Games"
Select="it.[SKU], it.[Name], it.[GSystem], it.[Rating]" OrderBy="it.[Name]">
</asp:EntityDataSource>
//------------------------------------------------
void GameSearchGrid_SelectedIndexChanged(object sender, EventArgs e)
{
GridViewRow row = GameSearchGrid.SelectedRow;
Response.Redirect("~/GameDetailView.aspx");
}
You can access bound fields using the
Cellsproperty on the row. The Cells property can only access cells by numerical index, so you would need to know the index of the column you want to access. For instance:If you don’t want to hard code the index you can look it up from the Columns property on the GridView by, for example, matching the HeaderText:
After that you can go ahead and redirect to the new page. Probably you would want to supply the found SKU value in the querystring:
Note that redirecting will cause the browser to issue a new request (a GET request), so the page you are redirecting to will not have access to the post data or any other data from the page before (with the exception of the SKU in the query string which is explicitly passed along).