Hi there,
Yes, it can be done. From a high level overview, this is what you need:
1. In DetailsView1_ItemInserted and DetailsView1_ItemUpdated retrieve the selected genre ID from the e argument and send it to EndEditing.
2. Modify EndEditing so it forwards the selected genre ID to the Reviews page
3. In Reviews.aspx, look at the query string (only when the page first loads, not after a postback) and set the SelectedValue on the Genre list when there is a valid genre ID. Here's the code to implement this:
1. (in AddEditReview.aspx.cs)
Code:
protected void DetailsView1_ItemInserted(object sender, DetailsViewInsertedEventArgs e)
{
int genreId = Convert.ToInt32(e.Values["GenreId"]);
EndEditing(genreId);
}
protected void DetailsView1_ItemUpdated(object sender, DetailsViewUpdatedEventArgs e)
{
int genreId = Convert.ToInt32(e.NewValues["GenreId"]);
EndEditing(genreId);
}
2. (in AddEditReview.aspx.cs)
Code:
private void EndEditing(int genreId)
{
Response.Redirect("Reviews.aspx?GenreId=" + genreId.ToString());
}
3. (In Reviews.aspx.cs)
Code:
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
string genreId = Request.QueryString.Get("GenreId");
if (!string.IsNullOrEmpty(genreId))
{
DropDownList1.SelectedValue = genreId;
}
}
}
You still run the risk that the new review is not on the first page of the GridView with reviews, but at least the correct genre has been selected.
Hope this helps,
Imar