Workshop






Workshop

Quiz

1.

How do you associate a data source control with a data Web control?

2.

True or False: A data source control can be used to display data.

3.

True or False: A data Web control can be used to retrieve data from a database.

4.

How can a DetailsView control be configured to allow the user to step through the records of its data source control?

5.

What are the formatting specifiers for formatting a numeric field as a currency? What about for formatting a date/time field as just a date?

Answers

1.

Add the data Web control to the page. In the data Web control's smart tag, a Choose Data Source drop-down list will list the data source controls on the page. Simply select the data source control that you want to bind to the data Web control.

2.

False. A data source control simply retrieves data from a database. It's up to a data Web control to display it.

3.

False. A data Web control merely displays data. It's the data source control that must get the data from the underlying data source. In this way, data source controls and data Web controls work in tandem.

4.

By default, the DetailsView control does not support paging. That means when visiting the page through a browser, the user will see just the first record in the data source control. To allow the user to step through all of the records in the associated data source control, you need to enable paging. You can do this by checking the Enable Paging check box in the DetailsView's smart tab or by setting the AllowPaging property to true in the Properties window.

5.

The format specifier for a currency is c. To display just the date portion of a date/time field, use d. To use these format specifiers in a GridView or DetailsView field, you need to set the HtmlEncode property to False and set the DataFormatString to {0:format specifier}.

Exercises

  1. Create a new ASP.NET page named MyBookTitles.aspx. Add a SqlDataSource control to the page and configure it to return only the Title column from the Books table, ordering the results alphabetically by Title. Next, add a GridView to the page and bind it to the SqlDataSource. Take a moment to format the GridView using the Auto Format dialog box.

    Test this page by visiting it through a web browser.

  2. Create another ASP.NET page, this one named MostRecentlyReadBook.aspx. Add a SqlDataSource that returns all columns from the Books table but orders them by LastReadDate in descending order. Next, add a DetailsView to the page and bind it to the data source control. Do not enable paging in the DetailsView.

    Customize the fields-level properties so that only the Title, Author, and LastReadOn fields are displayed, where the Title field is displayed in italics and the LastReadOn field is displayed in bold. Change the LastReadOn field's HeaderText property to Finished Reading On and have it formatted so only the date is displayed.

    Test this page by visiting it through a web browser.



 Python   SQL   Java   php   Perl 
 game development   web development   internet   *nix   graphics   hardware 
 telecommunications   C++ 
 Flash   Active Directory   Windows