Workshop

for RuBoard

This workshop will help reinforce the concepts covered in today's lesson.

Quiz

1:

What is the purpose of the Server Explorer in Visual Studio .NET?

A1:

The purpose of the Server Explorer, along with the visual designers in VS .NET, is to allow rapid application development for server-based and middle- tier components by providing a drag-and-drop interface for manipulating server resources such as databases, message queues, event logs, and performance counters.

2:

What three options does the Data Adapter Configuration Wizard provide for defining a query?

A2:

Using SQL statements typed in or built with the Query Builder, creating new stored procedures on the fly, or specifying existing stored procedures. Stored procedures are recommended for accessing a SQL Server database.

3:

How can you generate a DataSet from existing data adapters?

A3:

If you have data adapters defined on the designer, you can right-click on the designer and choose Generate DataSet. The resulting dialog allows you to choose which select commands from the data adapters will be used to generate the definition of the data tables in the DataSet .

4:

What is the purpose of template columns in a DataGrid control?

A4:

Template columns are used to provide alternative renderings for columns in the DataGrid . For example, you can provide a Label control for default viewing of the column and a DropDownList control for editing.

Exercise

Q1:

You'll notice that although we added a data adapter to read the Categories table and create a relation in the DataSet to relate the CatID columns in the Titles and Categories table, we didn't actually display a Categories column. In this exercise, modify the WebForm1.aspx page to add a read-only column to display the category description.

A1:

One simple technique that you can use to add the category description column to the grid is to first create a new template column in the grid. This can be accomplished programmatically by editing the HTML and adding the new Category column after the Price column as follows :

 <asp:TemplateColumn HeaderText="Category">  <ItemTemplate>   <asp:Label id="Label7" runat="server"     Text='<%# this.GetCategory(DataBinder.Eval(Container,"DataItem.CatId"))%>'>   </asp:Label>  </ItemTemplate> </asp:TemplateColumn> 

Note that this template column contains only an ItemTemplate tag because the column is not editable. The Text attribute passes the CatId column for the current row to a method on the page called GetCategory . This method should return the Description given the CatId as follows.

 protected string GetCategory(object CatId) {     dsTitles.CategoriesRow dr =      (dsTitles.CategoriesRow)dsTitles1.Categories.Select(      "CatID = '" + CatId.ToString() + "'")[0];     return dr.Description; } 

You'll learn more about the Select method used here tomorrow.

for RuBoard


Sams Teach Yourself Ado. Net in 21 Days
Sams Teach Yourself ADO.NET in 21 Days
ISBN: 0672323869
EAN: 2147483647
Year: 2002
Pages: 158
Authors: Dan Fox

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net