AspxGridView提供了从客户端与服务器端两种方式激活新增,编辑,删除面板。本节主要讲解如下从客户端激活各种面板:
1.新增
调用AddNewRow()方法打开新增面板:
方法定义:function AddNewRow();
2.修改
调用StartEditRow()使行进入编辑面板
方法定义:function StartEditRow(visibleIndex : int);
3.取消编辑状态
1),点击【取消】按钮或【保存按钮】自动取消编辑面板
2),调用CancelEdit()或UpdateEdit()取消编辑面板
4.删除
调用DeleteRow()方法实现数据删除。
方法定义:function DeleteRow(visibleIndex : int);
调用方法:在JavaScript中通过AspxGridView的"客户端名称.方法名称()"格式来调用。示例:下面演示如何实现通过双击数据来修改数据
<dxwgv:ASPxGridView ID="ASPxGridView1" runat="server" AutoGenerateColumns="False"
DataSourceID="ObjectDataSource1" KeyFieldName="PID" ClientInstanceName="Grid" >
<ClientSideEvents RowDblClick="function(s, e) {DblClick();}" / >
<SettingsText CommandCancel="取消" CommandUpdate="确定" PopupEditFormCaption="参数管理" / >
<SettingsEditing Mode="PopupEditForm" PopupEditFormHorizontalAlign="LeftSides" EditFormColumnCount="1"
PopupEditFormHorizontalOffset="200" PopupEditFormWidth="300px" / >
<Columns >
<dxwgv:GridViewDataTextColumn Caption="参数编号" FieldName="PID" >
<EditItemTemplate >
<asp:TextBox ID="pid_copy" runat="server" Enabled="false" Text='<%#Eval("PID") % >' ></asp:TextBox >
</EditItemTemplate >
<EditFormSettings Caption="参数编号:" / >
</dxwgv:GridViewDataTextColumn >
<dxwgv:GridViewDataTextColumn Caption="参数类型" FieldName="Type" >
<EditFormSettings Visible="False" / >
</dxwgv:GridViewDataTextColumn >
<dxwgv:GridViewDataTextColumn Caption="参数值" FieldName="Value" >
<PropertiesTextEdit >
<ValidationSettings CausesValidation="True" SetFocusOnError="True" >
<RequiredField IsRequired="True" / >
</ValidationSettings >
</PropertiesTextEdit >
<EditFormSettings Caption="参数值:" / >
</dxwgv:GridViewDataTextColumn >
<dxwgv:GridViewDataTextColumn Caption="描述" FieldName="Description" >
<EditFormSettings Visible="False" / >
</dxwgv:GridViewDataTextColumn >
</Columns >
</dxwgv:ASPxGridView >
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" SelectMethod="GetAllList" TypeName="SDERP.BLL.SysManage.Sys_Parameters" UpdateMethod="Update" >
<UpdateParameters >
<asp:FormParameter FormField="PID" Name="PID" Type="String" / >
<asp:FormParameter FormField="Value" Name="Value" Type="String" / >
</UpdateParameters >
</asp:ObjectDataSource >
<script type="text/javascript" language="javascript" >
function DblClick() {
Modify();
}
function Modify() {
Grid.StartEditRow(Grid.focusedRowIndex);
}
//注:Grid是前面定义的AspxGridView的客户端ID
</script >
下节我们学习如何通过服务器端来调上以上各方法。