1

"edit"单击 my 上的按钮时ASPxGridView,将触发StartRowEditing 事件。发生这种情况时,我设置了一个名为的局部变量,"IsEditing"这样当CellEditorIntialize触发时,我可以为我的comboboxes. 我这样做是因为如果用户按下取消,该CellEditorInitialize事件会再次触发,并且由于combobox不可用,我得到一个空引用问题。

我需要为"new"按钮做同样的事情,但没有"StartSrowInserting"事件。

有任何想法吗?

这是 C# 中的服务器代码。

这是 StartRowEditingEvent:

protected void gvLocation_StartRowEditing(object sender, DevExpress.Web.Data.ASPxStartRowEditingEventArgs e)
    {
        this.IsEditing = true; //There's not editing property in this event, so everytime it fires, we'll set this flag to true
        if (e.Cancel) //And we'll only set the flag to false when canceling
            this.IsEditing = false;
    }

当我单击 ASPxGridView 上的“编辑”按钮时,会触发此事件。它将将该变量设置为true。如果用户取消对话框,它将设置为 false。

然后当控件初始化时,CellEditorInitialize 事件触发。

protected void gvLocation_CellEditorInitialize(object sender, DevExpress.Web.ASPxGridView.ASPxGridViewEditorEventArgs e)
    {
        e.Column.EditFormSettings.Visible = DevExpress.Utils.DefaultBoolean.False;

        if (this.IsEditing) //Only populate fields when editing
        {
            if (e.Column.FieldName == "LocationPK")
                e.Editor.Visible = false; //We don't want LocationPK to be updated
            else if (e.Column.FieldName == "ShalePlay")
            {
                ASPxComboBox combo = (ASPxComboBox)e.Editor;
                mcCommon.Setup(ref combo, true, LookupValuesShalePlay.List, "Description", "PK");
            }
            else if (e.Column.FieldName == "FieldType")
            {
                ASPxComboBox combo = (ASPxComboBox)e.Editor;
                mcCommon.Setup(ref combo, true, LookupValuesFieldType.List, "Description", "PK");
            }
            else if (e.Column.FieldName == "County")
            {
                ASPxComboBox combo = (ASPxComboBox)e.Editor;
                mcCommon.Setup(ref combo, true, LookupValuesCounty.List, "Description", "PK");
            }
            else if (e.Column.FieldName == "State")
            {
                ASPxComboBox combo = (ASPxComboBox)e.Editor;
                mcCommon.Setup(ref combo, true, LookupValuesState.List, "Description", "PK");
            }
            else
            {

            }
        }
    }

我确定哪个控件是哪个并分配数据源。如果我不使用那个标志,当用户取消编辑时,它会抛出一个空异常。插入时,当用户单击“新建”或“取消”时也会触发此事件。但是在 CellEditorInitiliaze 触发之前,我找不到在单击“新建”按钮时触发的事件。

因此,当用户单击“新建”和“取消”按钮时,我需要一种方法来设置该标志,这样我就可以设置该标志。

这是 ASPxGridView 的标记。

<dx:ASPxGridView
ID="gvLocation"
runat="server"
AutoGenerateColumns="False"
DataSourceID="edsLocations"
ClientInstanceName="gvLocation"
ViewStateMode="Disabled"
KeyFieldName="LocationPK"
Width="600px"
OnCellEditorInitialize="gvLocation_CellEditorInitialize"
OnCommandButtonInitialize="gvLocation_CommandButtonInitialize"
OnStartRowEditing="gvLocation_StartRowEditing"
>
    <ClientSideEvents BeginCallback="
                    function(s, e) {loadingPanel.Show();}"
EndCallback="
                    function(s, e) {loadingPanel.Hide();}" />
<Columns>
    <dx:GridViewDataHyperLinkColumn FieldName="LocationPK" ReadOnly="True" VisibleIndex="0" Visible="false">
        <PropertiesHyperLinkEdit TextField="LocationPK" />
    </dx:GridViewDataHyperLinkColumn>
    <dx:GridViewDataTextColumn FieldName="LocationName" VisibleIndex="1">
         <DataItemTemplate>
            <a href="javascript:void(0);" onclick="gvLocation_LinkClick('<%# Container.VisibleIndex %>');"><%# DataBinder.Eval(Container.DataItem,"LocationName") %></a>
        </DataItemTemplate>
    </dx:GridViewDataTextColumn>
    <dx:GridViewDataComboBoxColumn FieldName="FieldType" VisibleIndex="2">
        <PropertiesComboBox TextField="FieldType" ValueField="FieldType" />
    </dx:GridViewDataComboBoxColumn>
    <dx:GridViewDataComboBoxColumn FieldName="State" VisibleIndex="4">
        <PropertiesComboBox ValueField="State" TextField="State" />
    </dx:GridViewDataComboBoxColumn>
    <dx:GridViewDataComboBoxColumn FieldName="CountyName" VisibleIndex="3">
        <PropertiesComboBox ValueField="CountyName" TextField="CountyName" ValueType="System.String" DataSourceID="edsCounty" />
    </dx:GridViewDataComboBoxColumn>
    <dx:GridViewDataComboBoxColumn FieldName="ShalePlay" VisibleIndex="5">
        <PropertiesComboBox ValueField="ShalePlay" TextField="ShalePlay" />
    </dx:GridViewDataComboBoxColumn>
    <dx:GridViewCommandColumn VisibleIndex="6">
        <EditButton Visible="True">
        </EditButton>
        <NewButton Visible="True">
        </NewButton>
    </dx:GridViewCommandColumn>
</Columns>
<Settings ShowFilterBar="Visible" ShowFilterRow="True" ShowGroupPanel="True" />
<SettingsBehavior AllowFocusedRow="True" />
<SettingsLoadingPanel Mode="Disabled" />

4

1 回答 1

3

您可以使用 ASPxGridView.InitNewRow 来捕获新插入的启动时间。然后,您可以使用 ASPxGridView.CancelRowEditing 来捕获取消。

http://documentation.devexpress.com/#AspNet/DevExpressWebASPxGridViewASPxGridView_InitNewRowtopic

http://documentation.devexpress.com/#AspNet/DevExpressWebASPxGridViewASPxGridView_CancelRowEditingtopic

于 2013-08-30T15:06:23.843 回答