문제

When the "edit" button is clicked on my ASPxGridView, the StartRowEditing event fires. When this occurs, I set a local variable called, "IsEditing" So that when CellEditorIntialize fires, I can set the datasource for my comboboxes. I do this because if the user presses cancel, that CellEditorInitialize event fires again and since the combobox isn't available, I get a null reference issue.

I need to do the same for the "new" button, but there's no "StartSrowInserting" event.

Any ideas?

Here's the server code, in C#.

This is the 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;
    }

When I click the "edit" button on the ASPxGridView, this event fires. It will set that variable to true. If the user is cancelling the dialog, it will set it to false.

Then as the controls initialize, the CellEditorInitialize event fires.

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
            {

            }
        }
    }

I determine which control is which and assign the data sources. If I don't use that flag, when the user cancels the edit, it will throw a null exception. This event also fires when the user clicks "New" or "Cancel", when inserting. But there's no event, that I can find, that fires when clicking the "new" button, before CellEditorInitiliaze fires.

So I need a way to set that flag when the user clicks the "new" and "cancel" buttons, so I can set the flag.

Here's the markup for the 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" />

도움이 되었습니까?

해결책

You can use ASPxGridView.InitNewRow to catch when the new insert is initiated. You can then use ASPxGridView.CancelRowEditing to catch a cancellation.

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

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top