03.11.2016 Views

Beginning ASP.NET 4.5 in CSharp and VB Opsylum

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

482 x CHAPTER 13 DISPLAYING AND UPDATING DATA<br />

DetailsView1.DefaultMode = DetailsViewMode.Edit<br />

End If<br />

End Sub<br />

C#<br />

protected void Page_Load(object sender, EventArgs e)<br />

{<br />

if (Request.QueryStr<strong>in</strong>g.Get("Id") != null)<br />

{<br />

DetailsView1.DefaultMode = DetailsViewMode.Edit;<br />

}<br />

}<br />

10. Open the Reviews.aspx page <strong>in</strong> Design View <strong>and</strong> drag the AddEditReview.aspx page from the<br />

Solution Explorer onto the page below the GridView. This creates a l<strong>in</strong>k to this page so you can<br />

<strong>in</strong>sert new reviews. Switch to Markup View <strong>and</strong> change the text between the tags to Insert<br />

New Review:<br />

Insert New Review<br />

11. Save all your changes <strong>and</strong> open AddEditReview.aspx <strong>in</strong> your browser. You should get the default<br />

layout for the control, with simple text boxes for all the columns <strong>in</strong> the data source. Fill <strong>in</strong> the<br />

fields as shown <strong>in</strong> Figure 13-18.<br />

FIGURE 13-18<br />

COMMON MISTAKES If you get an empty screen, make sure you set<br />

DefaultMode to Insert. Be sure the GenreId that you enter matches one of the<br />

genres <strong>in</strong> the Genre table <strong>in</strong> the database or you’ll get an error when you try to<br />

<strong>in</strong>sert the item. Also be sure you enter a valid date us<strong>in</strong>g the yyyy/mm/dd format,<br />

where y st<strong>and</strong>s for year, m for month, <strong>and</strong> d for day.<br />

Click Insert to <strong>in</strong>sert the item <strong>in</strong> the database. At first, not much seems to happen except that the<br />

controls are now all cleared. However, you can now locate the new review through the Reviews<br />

.aspx page by follow<strong>in</strong>g these two steps:

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!