<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Example2.aspx.cs" Inherits="Example2" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<div>
Pick Category:
<asp:DropDownList ID="CategoryList"
DataSourceID="CategoryDataSource"
DataTextField="CategoryName"
DataValueField="CategoryId"
AutoPostBack="true"
runat="server" />
</div>
<div style="color:Red;">
<asp:Literal ID="ErrorMessage" runat="server" EnableViewState="false" />
</div>
<asp:GridView ID="ProductGrid"
runat="server"
AllowPaging="True"
AllowSorting="True"
AutoGenerateColumns="False"
DataSourceID="ProductDataSource"
DataKeyNames="ProductId"
OnRowUpdated="ProductGrid_RowUpdated"
OnRowDeleted="ProductGrid_RowDeleted"
>
<Columns>
<asp:CommandField ShowEditButton="True" />
<asp:CommandField ShowDeleteButton="True" />
<asp:BoundField DataField="ProductName"
HeaderText="ProductName"
SortExpression="ProductName" />
<asp:TemplateField HeaderText="Supplier" SortExpression="Supplier.CompanyName">
<ItemTemplate>
<%# Eval("Supplier.CompanyName")%>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList ID="DropDownList1"
DataSourceID="SupplierDataSource"
DataValueField="SupplierId"
DataTextField="CompanyName"
SelectedValue='<%# Bind("SupplierId") %>'
runat="server" />
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Category" SortExpression="Category.CategoryName">
<ItemTemplate>
<%# Eval("Category.CategoryName")%>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList ID="DropDownList2"
DataSourceID="CategoryDataSource"
DataValueField="CategoryId"
DataTextField="CategoryName"
SelectedValue='<%# Bind("CategoryId") %>'
runat="server" />
</EditItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="UnitPrice"
HeaderText="UnitPrice"
SortExpression="UnitPrice" />
<asp:BoundField DataField="UnitsInStock"
HeaderText="UnitsInStock"
SortExpression="UnitsInStock" />
<asp:BoundField DataField="UnitsOnOrder"
HeaderText="UnitsOnOrder"
SortExpression="UnitsOnOrder" />
<asp:CheckBoxField DataField="Discontinued"
HeaderText="Discontinued"
SortExpression="Discontinued" />
</Columns>
</asp:GridView>
<iqw:DataSource ID="ProductDataSource"
runat="server"
ContextTypeName="Northwind"
TableName="Products"
Where="CategoryId == @CategoryId"
EnableDelete="true"
EnableUpdate="true"
EnableInsert="true">
<WhereParameters>
<asp:ControlParameter ControlID="CategoryList"
Name="CategoryId"
PropertyName="SelectedValue"
Type="Int32" />
</WhereParameters>
</iqw:DataSource>
<iqw:DataSource ID="CategoryDataSource"
runat="server"
ContextTypeName="Northwind"
TableName="Categories" />
<iqw:DataSource ID="SupplierDataSource"
runat="server"
ContextTypeName="Northwind"
TableName="Suppliers" />
</div>
</form>
</body>
</html>