четверг, 25 октября 2012 г.

6."Пейджинг" в ASP.NET из БД Oracle (Подготовка слоя пользовательского интерфейса).

Создаем страничку Default.aspx, и следующую аспх разметку:


<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Paging.Default" %>

<!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> 
     <asp:DropDownList runat="server"
                       ID="DropJobs"
                       Width="631px"
                       DataSourceID="JobsObjectDatasource"
                       DataValueField="jobId"
                       DataTextField="jobNm"
                       AutoPostBack="true" >
</asp:DropDownList>
<br />
<br />
<asp:GridView runat="server"
              ID="ListEmployees"
              DataSourceID="EmployeesObjectDatasource"
              AllowPaging="true"
              AllowSorting="true"
              AutoGenerateColumns="False"
              DataKeyNames="empId"
              Width="636px"
              AutoGenerateEditButton="true">
</asp:GridView>



<asp:ObjectDataSource runat="server"
                      ID="JobsObjectDatasource"
                      TypeName="Paging.BLLJobs"
                      SelectMethod="GetJobs" >
</asp:ObjectDataSource>

<asp:ObjectDataSource runat="server" ID="EmployeesObjectDatasource"
                      SortParameterName="EmployeesSort"
                      TypeName="Paging.BLLEmployees"
                      SelectMethod="GetEmployees"
                      SelectCountMethod="GetEmployeesCount"
                      UpdateMethod="UpdateEmployee"
                      EnablePaging="true">

<SelectParameters>
    <asp:ControlParameter  ControlID="DropJobs"
                           Name="jobId"
                           PropertyName="SelectedValue"
                           Type="Int32" />  
</SelectParameters>
<UpdateParameters>
    <asp:Parameter Name="empId"  Type="Int32"/>
    <asp:Parameter Name="Salary" Type="Double" />
</UpdateParameters>
</asp:ObjectDataSource>

    </div>
    </form>
</body>
</html>

Тут ничего особенного - всего лишь DropDownList и ObjectDataSource, на который он настроен. Для ObjectDataSource прописан SelectMethod="GetJobs" - т.е. при загрузке страницы стартует процесс извлечения данных из БД.
"ListEmployees" и "EmployeesObjectDatasource"  формируют таблицу с данными для Employees. Тут прописаны SelectMethod="GetEmployees" , SelectCountMethod="GetEmployeesCount" ,   EnablePaging="true"(нужны для пейджинга) и UpdateMethod="UpdateEmployee" для изменения записи в БД.


А в code behind нашей страницы Default.aspx пропишем настройки для колонок ListEmployees


 private BoundField empId;
   private BoundField fullName;
   private BoundField Salary;

    protected void Page_Init(object sender, EventArgs e)
    {
        empId = new BoundField();
        fullName = new BoundField();
        Salary = new BoundField();
     
        empId.DataField = "empId";
        empId.HeaderText = "ID";
        empId.Visible = false;
        ListEmployees.Columns.Add(empId);

     
        fullName.DataField = "fullName";
        fullName.HeaderText = "FullName";
        fullName.ReadOnly = true;
        fullName.SortExpression = fullName.DataField;
        ListEmployees.Columns.Add(fullName);

     
        Salary.DataField = "SALARY";
        Salary.HeaderText = "Salary";
        Salary.SortExpression = Salary.DataField;
        ListEmployees.Columns.Add(Salary);

    }

 protected void Page_Load(object sender, EventArgs e)
        {
         
        }

Вот, вроде бы и все...все вопросы пишите мне на andrtur@gmail.com




Комментариев нет:

Отправить комментарий