Databases Reference
In-Depth Information
namespace WebApplication.DynamicData.CustomPages.Orders
{
public partial class Details : System.Web.UI.Page
{
protected MetaTable ordersTable;
protected MetaTable itemsTable;
protected void Page_Init(object sender, EventArgs e)
{
this.ordersTable = DynamicDataRouteHandler.GetRequestMetaTable(this.Context);
this.Title = this.ordersTable.DisplayName;
this.formDataSource.Include = this.ordersTable.ForeignKeyColumnsNames;
this.itemsTable = Global.DefaultModel.GetTable(typeof(Order_Detail));
this.gridView.SetMetaTable(this.itemsTable);
}
protected void GridDataSource_Selected(object sender,
EntityDataSourceSelectedEventArgs e)
{
IEnumerable<Order_Detail> orderItems = e.Results.Cast<Order_Detail>();
decimal totalAmount = orderItems.Sum(item => item.UnitPrice * item.Quantity);
this.totalLiteral.Text = totalAmount.ToString();
}
}
}
The Page_Init event handler performs the remaining initialization steps, similar to how
this is done in the dynamic page templates. The first part of this method still relies on the
GetRequestMetaTable method of the DynamicDataRouteHandler class to retrieve the Orders
MetaTable using information in the URL route. This was simply carried over from the
dynamic Details page template. On the other hand, the Order Details MetaTable has to be
obtained directly from the default MetaModel object registered in the Global.asax . This
MetaTable object ( itemsTable ) is then associated with the GridView control to provide the
DynamicField instances access to the metadata information they need to instantiate
appropriate field templates.
The GridDataSource_Selected method handles the Selected event of the EntityDataSource
control that retrieves instances from the Order Details table. It calculates the total order
amount as a sum of UnitPrice values multiplied by the Quantity of the individual order
items. The result is then displayed in the Literal control on the page.
 
Search WWH ::




Custom Search