The EntitySpaces Community

Share and learn about the EntitySpaces Architecture.
Welcome to The EntitySpaces Community Sign in | Join | Help
in
Home Forums Photos

Inline GridView RUD via esDataSource

Last post 06-20-2007, 8:46 AM by Scott.Schecter. 0 replies.
Sort Posts: Previous Next
  •  06-20-2007, 8:46 AM 3296

    Inline GridView RUD via esDataSource

    Code:
    <%@ Page Language="C#" AutoEventWireup="true" Codebehind="MicrosoftInline.aspx.cs"
    Inherits="EntitySpaces.DataSource.Demo.MicrosoftInline" %>
    <%@ Register Assembly="EntitySpaces.Web" Namespace="EntitySpaces.Web" TagPrefix="cc1" %>

    <!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>Inline GridView CRUD</title>
    </head>
    <body>
    <form id="form1" runat="server">
    <asp:GridView ID="GridView1" runat="server" AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="EmployeeID" DataSourceID="EsDataSource1"
    AllowPaging="True" BackColor="White"
    BorderColor="#999999" BorderStyle="None" BorderWidth="1px" CellPadding="3" GridLines="Vertical"
    PageSize="5" AutoGenerateDeleteButton="True" AutoGenerateEditButton="True">
    <Columns>
    <asp:BoundField DataField="EmployeeID" HeaderText="EmployeeID" InsertVisible="False"
    ReadOnly="True" SortExpression="EmployeeID" />
    <asp:BoundField DataField="LastName" HeaderText="LastName" SortExpression="LastName" />
    <asp:BoundField DataField="FirstName" HeaderText="FirstName" SortExpression="FirstName" />
    <asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" />
    <asp:BoundField DataField="TitleOfCourtesy" HeaderText="TitleOfCourtesy" SortExpression="TitleOfCourtesy" />
    <asp:BoundField DataField="BirthDate" HeaderText="BirthDate" SortExpression="BirthDate" />
    <asp:BoundField DataField="HireDate" HeaderText="HireDate" SortExpression="HireDate" />
    </Columns>
    <FooterStyle BackColor="#CCCCCC" ForeColor="Black" />
    <RowStyle BackColor="#EEEEEE" ForeColor="Black" />
    <SelectedRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White" />
    <PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
    <HeaderStyle BackColor="#000084" Font-Bold="True" ForeColor="White" />
    <AlternatingRowStyle BackColor="Gainsboro" />
    </asp:GridView>
    <br />
    <cc1:esDataSource ID="EsDataSource1" runat="server" OnesSelect="EsDataSource1_esSelect"
    AutoPaging="true" AutoSorting="true" OnesCreateEntity="EsDataSource1_esCreateEntity" />
    </form>
    </body>
    </html>
    Code:
    using System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using BusinessObjects;

    namespace EntitySpaces.DataSource.Demo
    {
    public partial class MicrosoftInline : System.Web.UI.Page
    {
    protected void Page_Load(object sender, EventArgs e)
    {
    if (!Page.IsPostBack)
    {
    GetEmployeeCount();
    }
    }

    private void GetEmployeeCount()
    {
    Employees emp = new Employees();
    emp.Query.es.CountAll = true;
    emp.Query.es.CountAllAlias = "Count";
    if (emp.Query.Load())
    {
    EsDataSource1.TotalRowCount = (int)emp.GetColumn("Count");
    }

    GridView1.Sort(EmployeesMetadata.PropertyNames.LastName, SortDirection.Ascending);

    }

    protected void EsDataSource1_esSelect(object sender, EntitySpaces.Web.esDataSourceSelectEventArgs e)
    {
    EmployeesCollection employees = new EmployeesCollection();
    e.Collection = employees;
    }

    protected void EsDataSource1_esCreateEntity(object sender, EntitySpaces.Web.esDataSourceCreateEntityEventArgs e)
    {
    Employees employee = new Employees();
    if (e.PrimaryKeys == null)
    {
    employee.AddNew();
    }
    else
    {
    employee.LoadByPrimaryKey((int)e.PrimaryKeys[0]);
    }

    e.Entity = employee;
    }
    }
    }


    Regards,

    Scott Schecter
    EntitySpaces | My Site
View as RSS news feed in XML