Note that there are some explanatory texts on larger screens.

plurals
  1. POIs there a way to call some server side code when the "New" button is pressed?
    text
    copied!<p>When the <code>"edit"</code> button is clicked on my <code>ASPxGridView</code>, the <strong>StartRowEditing event</strong> fires. When this occurs, I set a local variable called, <code>"IsEditing"</code> So that when <strong>CellEditorIntialize</strong> fires, I can set the datasource for my <code>comboboxes</code>. I do this because if the user presses cancel, that <code>CellEditorInitialize</code> event fires again and since the <code>combobox</code> isn't available, I get a null reference issue.</p> <p>I need to do the same for the <code>"new"</code> button, but there's no <code>"StartSrowInserting"</code> event.</p> <p>Any ideas?</p> <p>Here's the server code, in C#.</p> <p>This is the StartRowEditingEvent:</p> <pre><code>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; } </code></pre> <p>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.</p> <p>Then as the controls initialize, the CellEditorInitialize event fires.</p> <pre><code>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 { } } } </code></pre> <p>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.</p> <p>So I need a way to set that flag when the user clicks the "new" and "cancel" buttons, so I can set the flag.</p> <p>Here's the markup for the ASPxGridView.</p> <pre><code>&lt;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" &gt; &lt;ClientSideEvents BeginCallback=" function(s, e) {loadingPanel.Show();}" EndCallback=" function(s, e) {loadingPanel.Hide();}" /&gt; &lt;Columns&gt; &lt;dx:GridViewDataHyperLinkColumn FieldName="LocationPK" ReadOnly="True" VisibleIndex="0" Visible="false"&gt; &lt;PropertiesHyperLinkEdit TextField="LocationPK" /&gt; &lt;/dx:GridViewDataHyperLinkColumn&gt; &lt;dx:GridViewDataTextColumn FieldName="LocationName" VisibleIndex="1"&gt; &lt;DataItemTemplate&gt; &lt;a href="javascript:void(0);" onclick="gvLocation_LinkClick('&lt;%# Container.VisibleIndex %&gt;');"&gt;&lt;%# DataBinder.Eval(Container.DataItem,"LocationName") %&gt;&lt;/a&gt; &lt;/DataItemTemplate&gt; &lt;/dx:GridViewDataTextColumn&gt; &lt;dx:GridViewDataComboBoxColumn FieldName="FieldType" VisibleIndex="2"&gt; &lt;PropertiesComboBox TextField="FieldType" ValueField="FieldType" /&gt; &lt;/dx:GridViewDataComboBoxColumn&gt; &lt;dx:GridViewDataComboBoxColumn FieldName="State" VisibleIndex="4"&gt; &lt;PropertiesComboBox ValueField="State" TextField="State" /&gt; &lt;/dx:GridViewDataComboBoxColumn&gt; &lt;dx:GridViewDataComboBoxColumn FieldName="CountyName" VisibleIndex="3"&gt; &lt;PropertiesComboBox ValueField="CountyName" TextField="CountyName" ValueType="System.String" DataSourceID="edsCounty" /&gt; &lt;/dx:GridViewDataComboBoxColumn&gt; &lt;dx:GridViewDataComboBoxColumn FieldName="ShalePlay" VisibleIndex="5"&gt; &lt;PropertiesComboBox ValueField="ShalePlay" TextField="ShalePlay" /&gt; &lt;/dx:GridViewDataComboBoxColumn&gt; &lt;dx:GridViewCommandColumn VisibleIndex="6"&gt; &lt;EditButton Visible="True"&gt; &lt;/EditButton&gt; &lt;NewButton Visible="True"&gt; &lt;/NewButton&gt; &lt;/dx:GridViewCommandColumn&gt; &lt;/Columns&gt; &lt;Settings ShowFilterBar="Visible" ShowFilterRow="True" ShowGroupPanel="True" /&gt; &lt;SettingsBehavior AllowFocusedRow="True" /&gt; &lt;SettingsLoadingPanel Mode="Disabled" /&gt; </code></pre> <p></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload