ASPxCardView.CardInserted Event
Fires after a new card has been added to the ASPxCardView.
Namespace: DevExpress.Web
Assembly: DevExpress.Web.v24.2.dll
Declaration
Event Data
The CardInserted event's data class is ASPxDataInsertedEventArgs. The following properties provide information specific to this event:
Property | Description |
---|---|
AffectedRecords | Gets the number of records affected by the update operation. Inherited from ASPxDataBaseUpdatedEventArgs. |
Exception | Gets the exception (if any) that was raised during the update operation. Inherited from ASPxDataBaseUpdatedEventArgs. |
ExceptionHandled | Gets or sets whether an exception raised during the update operation was handled in the event handler. Inherited from ASPxDataBaseUpdatedEventArgs. |
NewValues | Gets a dictionary that contains the values of the non-key field name/value pairs in the row to be inserted. |
Remarks
End-users can create new cards by clicking the New command. To create cards in code, use the ASPxCardView.AddNewCard method. To save the newly created card, end-users must click the Update command.
To cancel the insert operation, handle the ASPxCardView.CardInserting event.
Note
The CardInserted event fires even though an exception occurs during the data update operation. Use the ASPxDataBaseUpdatedEventArgs.Exception and ASPxDataBaseUpdatedEventArgs.ExceptionHandled argument properties to determine whether or not any exception occurs during the corresponding action, and handle it if you wish.
Example
The code sample below demonstrates how to focus a newly inserted card. Handle the CardInserted
event to get a key value of the card. Call the FindVisibleIndexByKeyValue(Object) method to get the card’s visible index. Then set the FocusedCardIndex property.
<dx:ASPxCardView ID="ASPxCardView1" runat="server" AutoGenerateColumns="False" DataSourceID="XpoDataSource1"
KeyFieldName="Oid" OnCardInserted="ASPxCardView1_CardInserted">
<SettingsPager>
<SettingsTableLayout ColumnCount="2" RowsPerPage="2" />
</SettingsPager>
<SettingsBehavior AllowFocusedCard="True" />
<Columns>
<dx:CardViewTextColumn FieldName="Oid" ReadOnly="True"
SortIndex="0" SortOrder="Ascending" Visible="False" />
<dx:CardViewTextColumn FieldName="CompanyName" />
<dx:CardViewTextColumn FieldName="ContactName" />
<dx:CardViewTextColumn FieldName="Country" />
</Columns>
<CardLayoutProperties>
<Items>
<dx:CardViewCommandLayoutItem HorizontalAlign="Right" ShowEditButton="True" ShowNewButton="True" />
<dx:CardViewColumnLayoutItem ColumnName="Oid" />
<dx:CardViewColumnLayoutItem ColumnName="Company Name" />
<dx:CardViewColumnLayoutItem ColumnName="Contact Name" />
<dx:CardViewColumnLayoutItem ColumnName="Country" />
<dx:EditModeCommandLayoutItem HorizontalAlign="Right" />
</Items>
</CardLayoutProperties>
</dx:ASPxCardView>
protected void ASPxCardView1_CardInserted(object sender, DevExpress.Web.Data.ASPxDataInsertedEventArgs e) {
object newKey = null;
if (e.AffectedRecords == 1)
{
ICollection objects = uof.GetObjectsToSave();
if (objects != null && objects.Count == 1)
{
IEnumerator enumeration = objects.GetEnumerator();
enumeration.MoveNext();
Customer obj = (Customer)enumeration.Current;
uof.CommitChanges();
newKey = obj.Oid;
}
}
ASPxCardView1.FocusedCardIndex = ASPxCardView1.FindVisibleIndexByKeyValue(newKey);
}