To setup selection for the grid, I changed the grid
definition to the following:
Listing 10
<asp:GridView … AutoGenerateSelectButton="true"
OnSelectedIndexChanging="gvwOrders_SelectedIndexChanging">
To select the grid when the grid is bound manually, the
SelectedIndexChanging event needs handled so that the grid can be rebound to
show the current selected item.
Listing 11
protected void gvwOrders_SelectedIndexChanging(object sender,
GridViewSelectEventArgs e)
{
GridView grid = (GridView)sender;
HiddenField customerKeyField = (HiddenField)grid.FindControl("hdnCustomerKey");
this.BindGrid(grid, new Guid(customerKeyField.Value));
}
Using the BindGrid refactoring, passing in the grid works
well to incorporate two scenarios. However, you do not really need to handle
the selection approach from the grid (in a manual bind scenario).