layout

第二种后台实现代码,比前一种更加好理解,但是代码量要多一点
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DevExpress.Web.ASPxEditors;
using DevExpress.Web.ASPxFormLayout;
using DevExpress.Web.Data;
using DevExpress.Web.ASPxGridView;


namespace ERP.Web.Sales.Price
{
    public partial class WholesaleDiscount1 : System.Web.UI.Page
    {
        OrderedDictionary newValues;
        protected void Page_Load(object sender, EventArgs e)
        {
            
        }

        protected void grid_RowUpdating(object sender, ASPxDataUpdatingEventArgs e)
        {
            //this.newValues = e.NewValues;
            //PopulateNewValues();
            ASPxFormLayout form = (ASPxFormLayout)grid.FindEditFormTemplateControl("Layout1");
            e.NewValues["单号"] = (string)form.GetNestedControlValueByFieldName("单号");
            e.NewValues["财务月份"] = (string)form.GetNestedControlValueByFieldName("财务月份");
            e.NewValues["办事处"] = (string)form.GetNestedControlValueByFieldName("办事处");
            e.NewValues["制单人"] = (string)form.GetNestedControlValueByFieldName("制单人");
            e.NewValues["制单日期"] = (DateTime)form.GetNestedControlValueByFieldName("制单日期");
            e.NewValues["状态"] = Int32.Parse(((string)form.GetNestedControlValueByFieldName("状态")));
            e.NewValues["关闭"] = (Boolean)form.GetNestedControlValueByFieldName("关闭");
        } 
        protected void grid_RowInserting(object sender, ASPxDataInsertingEventArgs e)
        {
            //this.newValues = e.NewValues;
            //PopulateNewValues();
            ASPxFormLayout form =(ASPxFormLayout)grid.FindEditFormTemplateControl("Layout1");
            e.NewValues["单号"] = (string)form.GetNestedControlValueByFieldName("单号");
            e.NewValues["财务月份"] = (string)form.GetNestedControlValueByFieldName("财务月份");
            e.NewValues["办事处"] = (string)form.GetNestedControlValueByFieldName("办事处");
            e.NewValues["制单人"] = (string)form.GetNestedControlValueByFieldName("制单人");
            e.NewValues["制单日期"] = (DateTime)form.GetNestedControlValueByFieldName("制单日期");
            e.NewValues["状态"] = Int32.Parse(((string)form.GetNestedControlValueByFieldName("状态")));
            e.NewValues["关闭"] = (Boolean)form.GetNestedControlValueByFieldName("关闭");

        }
      
        private void PopulateNewValues()
        {
            ASPxFormLayout formLayout = (ASPxFormLayout)grid.FindEditFormTemplateControl("Layout1");
            formLayout.ForEach(ProcessItem);
        }

        private void ProcessItem(LayoutItemBase item)
        {
            LayoutItem layoutItem = item as LayoutItem;
            if (layoutItem != null)
            {
                ASPxEditBase editBase = layoutItem.GetNestedControl() as ASPxEditBase;
                if (editBase != null)
                    this.newValues[layoutItem.FieldName] = editBase.Value;
            }
        }

       

    }
}

 

using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DevExpress.Web.ASPxEditors;
using DevExpress.Web.ASPxFormLayout;
using DevExpress.Web.Data;

namespace ERP.Web.Sales.Price
{
    public partial class WholesaleDiscount1 : System.Web.UI.Page
    {
        OrderedDictionary newValues;
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void grid_RowUpdating(object sender, ASPxDataUpdatingEventArgs e)
        {
            this.newValues = e.NewValues;
            PopulateNewValues();
        } 
        protected void grid_RowInserting(object sender, ASPxDataInsertingEventArgs e)
        {
            this.newValues = e.NewValues;
            PopulateNewValues();
        }
      
        private void PopulateNewValues()
        {
            ASPxFormLayout formLayout = (ASPxFormLayout)grid.FindEditFormTemplateControl("Layout1");
            formLayout.ForEach(ProcessItem);
        }

        private void ProcessItem(LayoutItemBase item)
        {
            LayoutItem layoutItem = item as LayoutItem;
            if (layoutItem != null)
            {
                ASPxEditBase editBase = layoutItem.GetNestedControl() as ASPxEditBase;
                if (editBase != null)
                    this.newValues[layoutItem.FieldName] = editBase.Value;
            }
        }

       

    }
}

  

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WholesaleDiscount1.aspx.cs" Inherits="ERP.Web.Sales.Price.WholesaleDiscount1" %>

<%@ Register assembly="DevExpress.Web.v13.1, Version=13.1.7.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" namespace="DevExpress.Web.ASPxFormLayout" tagprefix="dx" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
    </div>
        <dx:ASPxGridView ID="grid" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" KeyFieldName="单号" OnRowUpdating="grid_RowUpdating" OnRowInserting="grid_RowInserting" >
            <Columns>
                <dx:GridViewCommandColumn VisibleIndex="0">
                    <editbutton visible="True">
                    </editbutton>
                    <newbutton visible="True">
                    </newbutton>
                    <deletebutton visible="True">
                    </deletebutton>
                </dx:GridViewCommandColumn>
                <dx:GridViewDataTextColumn FieldName="单号" ReadOnly="True" VisibleIndex="1">
                </dx:GridViewDataTextColumn>
                <dx:GridViewDataTextColumn FieldName="财务月份" VisibleIndex="2">
                </dx:GridViewDataTextColumn>
                <dx:GridViewDataTextColumn FieldName="办事处" VisibleIndex="3">
                </dx:GridViewDataTextColumn>
                <dx:GridViewDataTextColumn FieldName="制单人" VisibleIndex="4">
                </dx:GridViewDataTextColumn>
                <dx:GridViewDataDateColumn FieldName="制单日期" VisibleIndex="5">
                </dx:GridViewDataDateColumn>
                <dx:GridViewDataTextColumn FieldName="状态" VisibleIndex="6">
                </dx:GridViewDataTextColumn>
                <dx:GridViewDataCheckColumn FieldName="关闭" VisibleIndex="7">
                </dx:GridViewDataCheckColumn>
            </Columns>
            <settings showfilterbar="Visible" showfilterrow="True" />
            <settingstext commandcancel="取消" commanddelete="删除" commandedit="编辑" commandnew="新增" commandupdate="更新" confirmdelete="确认删除" />
            <templates>
                <editform>
                    <dx:ASPxFormLayout ID="Layout1" runat="server" ColCount="3">
                        <Items>
                            <dx:LayoutItem Caption="  单号  " RequiredMarkDisplayMode="Required" FieldName="单号">
                                <layoutitemnestedcontrolcollection>
                                    <dx:LayoutItemNestedControlContainer runat="server" SupportsDisabledAttribute="True">
                                        <dx:ASPxTextBox ID="ASPxFormLayout1_E1" runat="server" Width="170px" Text='<%# Eval("单号") %>'>
                                        </dx:ASPxTextBox>
                                    </dx:LayoutItemNestedControlContainer>
                                </layoutitemnestedcontrolcollection>
                            </dx:LayoutItem> 
                            <dx:LayoutItem Caption="财务月份" RequiredMarkDisplayMode="Required" FieldName="财务月份">
                                <layoutitemnestedcontrolcollection>
                                    <dx:LayoutItemNestedControlContainer runat="server" SupportsDisabledAttribute="True">
                                        <dx:ASPxTextBox ID="ASPxFormLayout1_E2" runat="server" Width="170px" Text='<%# Eval("财务月份") %>'>
                                        </dx:ASPxTextBox>
                                    </dx:LayoutItemNestedControlContainer>
                                </layoutitemnestedcontrolcollection>
                            </dx:LayoutItem>
                            <dx:LayoutItem Caption="办事处" RequiredMarkDisplayMode="Required" FieldName="办事处">
                                <layoutitemnestedcontrolcollection>
                                    <dx:LayoutItemNestedControlContainer runat="server" SupportsDisabledAttribute="True">
                                        <dx:ASPxComboBox ID="ASPxFormLayout1_E3" runat="server" Text='<%# Eval("办事处") %>'>
                                        </dx:ASPxComboBox>
                                    </dx:LayoutItemNestedControlContainer>
                                </layoutitemnestedcontrolcollection>
                            </dx:LayoutItem>
                            <dx:LayoutItem Caption="制单人" RequiredMarkDisplayMode="Required" FieldName="制单人">
                                <layoutitemnestedcontrolcollection>
                                    <dx:LayoutItemNestedControlContainer runat="server" SupportsDisabledAttribute="True">
                                        <dx:ASPxTextBox ID="ASPxFormLayout1_E4" runat="server" Width="170px" Text='<%# Eval("制单人") %>'>
                                        </dx:ASPxTextBox>
                                    </dx:LayoutItemNestedControlContainer>
                                </layoutitemnestedcontrolcollection>
                            </dx:LayoutItem>
                            <dx:LayoutItem Caption="   状  态  " RequiredMarkDisplayMode="Required" FieldName="状态">
                                <layoutitemnestedcontrolcollection>
                                    <dx:LayoutItemNestedControlContainer runat="server" SupportsDisabledAttribute="True">
                                        <dx:ASPxComboBox ID="ASPxFormLayout1_E6" runat="server" Text='<%# Eval("状态") %>'>
                                        </dx:ASPxComboBox>
                                    </dx:LayoutItemNestedControlContainer>
                                </layoutitemnestedcontrolcollection>
                            </dx:LayoutItem>
                            <dx:LayoutItem Caption="  关闭  " RequiredMarkDisplayMode="Required" FieldName="关闭">
                                <layoutitemnestedcontrolcollection>
                                    <dx:LayoutItemNestedControlContainer runat="server" SupportsDisabledAttribute="True">
                                        <dx:ASPxCheckBox ID="ASPxFormLayout1_E7" runat="server" CheckState="Unchecked" Text='<%# Eval("关闭") %>'>
                                        </dx:ASPxCheckBox>
                                    </dx:LayoutItemNestedControlContainer>
                                </layoutitemnestedcontrolcollection>
                            </dx:LayoutItem>
                            <dx:LayoutItem Caption="制单日期" RequiredMarkDisplayMode="Required" FieldName="制单日期" ColSpan="2">
                                <layoutitemnestedcontrolcollection>
                                    <dx:LayoutItemNestedControlContainer runat="server" SupportsDisabledAttribute="True">
                                        <dx:ASPxCalendar ID="ASPxFormLayout1_E5" runat="server" Text='<%# Eval("制单日期") %>'>
                                        </dx:ASPxCalendar>
                                    </dx:LayoutItemNestedControlContainer>
                                </layoutitemnestedcontrolcollection>
                            </dx:LayoutItem>
                        </Items>
                    </dx:ASPxFormLayout>
                    <div>
                        <dx:ASPxGridViewTemplateReplacement runat="server" ID="上传" ReplacementType="EditFormUpdateButton">

                        </dx:ASPxGridViewTemplateReplacement>
                        <dx:ASPxGridViewTemplateReplacement ID="取消" runat="server" ReplacementType="EditFormCancelButton" />
                    </div>
                </editform>
            </templates>
        </dx:ASPxGridView>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:cobosdConnectionString %>" 
            DeleteCommand="DELETE FROM [ac_员工激励] WHERE [单号] = @单号" 
            InsertCommand="INSERT INTO [ac_员工激励] ([单号], [财务月份], [办事处], [制单人], [制单日期], [状态], [关闭]) VALUES (@单号, @财务月份, @办事处, @制单人, @制单日期, @状态, @关闭)"
            SelectCommand="SELECT * FROM [ac_员工激励]" 
            UpdateCommand="UPDATE [ac_员工激励] SET [财务月份] = @财务月份, [办事处] = @办事处, [制单人] = @制单人, [制单日期] = @制单日期, [状态] = @状态, [关闭] = @关闭 WHERE [单号] = @单号">
            <DeleteParameters>
                <asp:Parameter Name="单号" Type="String" />
            </DeleteParameters>
            <InsertParameters>
                <asp:Parameter Name="单号" Type="String" />
                <asp:Parameter Name="财务月份" Type="String" />
                <asp:Parameter Name="办事处" Type="String" />
                <asp:Parameter Name="制单人" Type="String" />
                <asp:Parameter Name="制单日期" Type="DateTime" />
                <asp:Parameter Name="状态" Type="Int32" />
                <asp:Parameter Name="关闭" Type="Boolean" />
            </InsertParameters>
            <UpdateParameters>
                <asp:Parameter Name="财务月份" Type="String" />
                <asp:Parameter Name="办事处" Type="String" />
                <asp:Parameter Name="制单人" Type="String" />
                <asp:Parameter Name="制单日期" Type="DateTime" />
                <asp:Parameter Name="状态" Type="Int32" />
                <asp:Parameter Name="关闭" Type="Boolean" />
                <asp:Parameter Name="单号" Type="String" />
            </UpdateParameters>
        </asp:SqlDataSource>
    </form>
</body>
</html>

  

下面的update和cancel按钮换了一个
                <div>
                        <table>
                            <tr>
                                <td>
                                    <dx:ASPxButton runat="server" Text="保存" AutoPostBack="False">
                                                            <clientsideevents click="function(s, e) {
	                                    grid.UpdateEdit();
                                    }" />
                                                            </dx:ASPxButton>
                                </td>
                                <td>
                                    
                                </td>
                                <td>
                                     <dx:ASPxButton runat="server" Text="取消" AutoPostBack="False">
                                                            <clientsideevents click="function(s, e) {
	                                    grid.CancelEdit();
                                    }" />
                                                            </dx:ASPxButton>
                                </td>
                            </tr>
                        </table>
                    </div>

  接下来就是这个样子了

posted @ 2013-10-31 15:11  南修子  阅读(1163)  评论(0编辑  收藏  举报