aspxgridview只编辑某一列然后更新

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="IsAllowDelivery.aspx.cs" Inherits="ERP.Web.Finance.Agent.IsAllowDelivery" %>

<%@ Register assembly="DevExpress.Web.v12.2, Version=12.2.8.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" namespace="DevExpress.Data.Linq" tagprefix="dx" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <script type="text/javascript">
        
    </script>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        
        <dx:ASPxButton ID="ASPxButton1" runat="server" OnClick="ASPxButton1_Click" Text="保存">
        </dx:ASPxButton>
        
    </div>
    <div>
        <dx:ASPxGridView ID="ASPxGridView1" runat="server" AutoGenerateColumns="False" ClientInstanceName="grid1" DataSourceID="SqlDataSource1" KeyFieldName="代码" Width="266px" OnRowUpdating="ASPxGridView1_RowUpdating">
            <clientsideevents rowclick="function(s, e) {
    grid1.StartEditRow(e.visibleIndex);
}" />
            <Columns>
                <dx:GridViewDataTextColumn FieldName="代码" ReadOnly="True" VisibleIndex="0" Width="80px">
                    <editcellstyle horizontalalign="Center">
                    </editcellstyle>
                   <DataItemTemplate>  
                         <asp:Label id="Label4" runat="server" Text='<%# Eval("代码") %>' Width="50px" />  
                   </DataItemTemplate>  
                   <EditItemTemplate>  
                         <asp:Label id="Label1" runat="server" Text='<%# Eval("代码") %>' Width="50px" />  
                   </EditItemTemplate>  
                    <cellstyle horizontalalign="Center">
                    </cellstyle>
                </dx:GridViewDataTextColumn>

                <dx:GridViewDataTextColumn FieldName="名称" ReadOnly="True" VisibleIndex="1" Width="80px">
                     <editcellstyle horizontalalign="Center">
                     </editcellstyle>
                     <DataItemTemplate>  
                         <asp:Label id="Label2" runat="server" Text='<%# Eval("名称") %>' />  
                     </DataItemTemplate>  
                     <EditItemTemplate>  
                         <asp:Label id="Label3" runat="server" Text='<%# Eval("名称") %>' />  
                     </EditItemTemplate>  
                     <cellstyle horizontalalign="Center">
                     </cellstyle>
                </dx:GridViewDataTextColumn>
                <dx:GridViewDataCheckColumn FieldName="是否允许发货" VisibleIndex="2" Width="50px">
                   <editcellstyle horizontalalign="Center" verticalalign="Middle" wrap="True">
                     </editcellstyle>
                     <editformcaptionstyle horizontalalign="Center">
                     </editformcaptionstyle>
                     <EditItemTemplate>
                         <dx:ASPxCheckBox ID="edits" runat="server" ClientInstanceName="edit" Checked='<%# Eval("是否允许发货") %>' >
                             <clientsideevents checkedchanged="function(s, e) {
    grid1.UpdateEdit();    
}" />          /dx:ASPxCheckBox>
                     </EditItemTemplate>

                     <cellstyle horizontalalign="Center" verticalalign="Middle" wrap="True">
                     </cellstyle>
                </dx:GridViewDataCheckColumn>
            </Columns>
            <settingsbehavior allowselectbyrowclick="True" />
            <settingspager pagesize="20">
            </settingspager>
            <settingsediting mode="Inline" />
        </dx:ASPxGridView>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:cobosdConnectionString %>" DeleteCommand="DELETE FROM [xs_办事处档案] WHERE [代码] = @original_代码" InsertCommand="INSERT INTO [xs_办事处档案] ([代码], [名称], [是否允许发货]) VALUES (@代码, @名称, @是否允许发货)" OldValuesParameterFormatString="original_{0}" SelectCommand="SELECT [代码], [名称], [是否允许发货] FROM [xs_办事处档案]" UpdateCommand="UPDATE [xs_办事处档案] SET [名称] = @名称, [是否允许发货] = @是否允许发货 WHERE [代码] = @original_代码">
            <DeleteParameters>
                <asp:Parameter Name="original_代码" Type="String" />
            </DeleteParameters>
            <InsertParameters>
                <asp:Parameter Name="代码" Type="String" />
                <asp:Parameter Name="名称" Type="String" />
                <asp:Parameter Name="是否允许发货" Type="Boolean" />
            </InsertParameters>
            <UpdateParameters>
                <asp:Parameter Name="名称" Type="String" />
                <asp:Parameter Name="是否允许发货" Type="Boolean" />
                <asp:Parameter Name="original_代码" Type="String" />
            </UpdateParameters>
        </asp:SqlDataSource>
    </div>
    </form>
</body>
</html>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using DevExpress.Web.ASPxEditors;
using DevExpress.Web.ASPxGridView;
namespace ERP.Web.Finance.Agent
{
    public partial class IsAllowDelivery : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void ASPxButton1_Click(object sender, EventArgs e)
        {
            ASPxGridView1.UpdateEdit();
        }

        protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
        {
            
            ASPxGridView1.UpdateEdit();
        }

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

        protected void ASPxGridView1_RowUpdating(object sender, DevExpress.Web.Data.ASPxDataUpdatingEventArgs e)
        {

            ASPxCheckBox ck = (ASPxCheckBox)ASPxGridView1.FindEditRowCellTemplateControl((GridViewDataColumn)ASPxGridView1.Columns["是否允许发货"], "edits");
            e.NewValues["是否允许发货"] = ck.Checked;
        }
    }
}

 

posted @ 2013-07-24 17:06  南修子  阅读(1403)  评论(0编辑  收藏  举报