有没有一种方法可以调用某些服务器端代码;新的“;按钮被按下
本文关键字:新的 代码 服务器端 按钮 一种 方法 调用 有没有 | 更新日期: 2023-09-27 18:29:35
在我的ASPxGridView
上单击"edit"
按钮时,将触发StartRowEditing事件。发生这种情况时,我会设置一个名为"IsEditing"
的局部变量,这样当CellEditorIntialize触发时,我就可以为我的comboboxes
设置数据源。我这样做是因为,如果用户按下cancel,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
{
}
}
}
我确定哪个控件是哪个,并分配数据源。如果我不使用该标志,当用户取消编辑时,它将抛出一个null异常。当用户在插入时单击"新建"或"取消"时,也会触发此事件。但在CellEditorInitilize启动之前,我找不到在单击"新建"按钮时启动的事件。
因此,当用户单击"新建"answers"取消"按钮时,我需要一种设置标志的方法,这样我就可以设置标志。
这是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" />
您可以使用ASPxGridView.InitNewRow来捕获新插入的启动时间。然后,您可以使用ASPxGridView.CancelRowEditing捕获取消。
http://documentation.devexpress.com/#AspNet/DevExpressWebASPxGridViewASPxGridView_InitNewRowtopic
http://documentation.devexpress.com/#AspNet/DevExpressWebASPxGridViewASPxGridView_CancelRowEditingtopic