p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   BOOK: Beginning ASP.NET 4 : in C# and VB (http://p2p.wrox.com/forumdisplay.php?f=560)
-   -   Creating a query for the Review.aspx (http://p2p.wrox.com/showthread.php?t=84954)

ronix September 5th, 2011 04:31 AM

Creating a query for the Review.aspx
 
Hi .

I just finished to read chapter 13 in this fantastic book .

I wanted to change something in my reviews.aspx page that it'll have a query, that's because i wanted that after i insert/update a new review with the DetailsView and push the insert button (or update), it'll redirect me to the reviews page of the right GenreID that just have been Insterted/update, and the situation now is that it redirect me only to the Reviews.aspx page and i have to look for my new/updated record by selecting the GenreID.
Is that possible to do ? if so, where should i tweak to make it happen ?

Thanks a lot !

Roni .

Imar September 5th, 2011 06:37 AM

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

ronix September 5th, 2011 06:46 AM

Thanks so much Imar ! you are amazing with the way you explain, and the attention you give to every question .
Your book is fantastic and i recommended it already to a few friends that bought it, and will keep recommend it as it great for beginners..

Thanks ! :) Roni .

Imar September 5th, 2011 06:50 AM

Quote:

Your book is fantastic and i recommended it already to a few friends that bought it, and will keep recommend it as it great for beginners..
Thank you. Much appreciated!

Imar


All times are GMT -4. The time now is 02:54 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.