Datasheet
6. Double-click the Fetch button to switch to the Click event procedure. Add the following code:
void Button1_Click(object sender, EventArgs e) {
DataGrid1.DataSource =
GetProducts(Convert.ToInt32(lstCategory.SelectedValue));
DataGrid1.DataBind();
}
7. Underneath that procedure, add the following code:
void Page_Load(Object Sender, EventArgs e)
{
if (!Page.IsPostBack) {
lstCategory.DataSource = GetCategories();
lstCategory.DataValueField = "CategoryID";
lstCategory.DataTextField = "CategoryName";
lstCategory.DataBind();
}
}
8. Underneath the preceding block of code, drag a SELECT Data Method wizard from the toolbox
onto the page. Pick the current database connection and select the
CategoryID and
CategoryName columns from the Categories table. Call the procedure that you have created
GetCategories and have it return a DataSet.
9. Drag another SELECT Data Method wizard onto the page, underneath the SELECT Data Method
wizard that you just created. Pick the current database connection, and select ProductName,
QuantityPerUnit, UnitPrice, and UnitsInStock from the Products table.
10. Click the WHERE button and pick the CategoryID from the Products table making it Filter on
@CategoryID, as shown in Figure 8-21:
Figure 8-21
11. Click OK and Next to get to the Name Method screen.
12. Call the procedure GetProducts and have it return a DataSet. Press Finish to insert the code.
274
Chapter 8
57084_08.qxp 30/01/2004 8:03 PM Page 274