Use the EditingRowVisibleIndex property to identify the data row currently being edited by an end-user. This can be useful when the focused row feature is disabled (the ASPxGridViewBehaviorSettings.AllowFocusedRow property is set to false). Otherwise, if the focused row is enabled, you can also use the ASPxGridView.FocusedRowIndex property.
<h1>How to use ASPxListBox inside the EditForm for editing ASPxGridView</h1><dx:ASPxGridViewID="ASPxGridView1"runat="server"AutoGenerateColumns="False"DataSourceID="AccessDataSource1"KeyFieldName="CategoryID"OnRowUpdating="ASPxGridView1_RowUpdating"OnRowValidating="ASPxGridView1_RowValidating"><Columns><dx:GridViewCommandColumnVisibleIndex="0"ShowEditButton="true"></dx:GridViewCommandColumn><dx:GridViewDataTextColumnFieldName="CategoryID"ReadOnly="True"VisibleIndex="0"><EditFormSettingsVisible="False" /></dx:GridViewDataTextColumn><dx:GridViewDataTextColumnFieldName="CategoryName"VisibleIndex="1"></dx:GridViewDataTextColumn><dx:GridViewDataTextColumnFieldName="Description"VisibleIndex="2"></dx:GridViewDataTextColumn></Columns><Templates><EditForm><dx:ASPxListBoxID="ASPxListBox1"runat="server"DataSourceID="AccessDataSource2"SelectionMode="CheckColumn"TextField="ProductName"ValueField="ProductName"ValueType="System.String"OnDataBound="ASPxListBox1_DataBound"></dx:ASPxListBox><br /><dx:ASPxGridViewTemplateReplacementID="btnUpdate"runat="server"ReplacementType="EditFormUpdateButton"></dx:ASPxGridViewTemplateReplacement><dx:ASPxGridViewTemplateReplacementID="btnCancel"runat="server"ReplacementType="EditFormCancelButton"></dx:ASPxGridViewTemplateReplacement></EditForm></Templates></dx:ASPxGridView></div><asp:AccessDataSourceID="AccessDataSource1"runat="server"DataFile="~/App_Data/nwind.mdb"SelectCommand="SELECT [CategoryID], [CategoryName], [Description] FROM [Categories]"DeleteCommand="DELETE FROM [Categories] WHERE [CategoryID] = ?"InsertCommand="INSERT INTO [Categories] ([CategoryID], [CategoryName], [Description]) VALUES (?, ?, ?)"UpdateCommand="UPDATE [Categories] SET [CategoryName] = ?, [Description] = ? WHERE [CategoryID] = ?"><DeleteParameters><asp:ParameterName="CategoryID"Type="Int32" /></DeleteParameters><UpdateParameters><asp:ParameterName="CategoryName"Type="String" /><asp:ParameterName="Description"Type="String" /><asp:ParameterName="CategoryID"Type="Int32" /></UpdateParameters><InsertParameters><asp:ParameterName="CategoryID"Type="Int32" /><asp:ParameterName="CategoryName"Type="String" /><asp:ParameterName="Description"Type="String" /></InsertParameters></asp:AccessDataSource><asp:AccessDataSourceID="AccessDataSource2"runat="server"DataFile="~/App_Data/nwind.mdb"SelectCommand="SELECT [ProductName] FROM [Products]"></asp:AccessDataSource>
usingDevExpress.Web;
publicpartialclass _Default : System.Web.UI.Page {
protectedvoidPage_Load(object sender, EventArgs e) {
}
protectedvoidASPxListBox1_DataBound(object sender, EventArgs e) {
var listBox = (ASPxListBox)sender;
int editingRowVisibleIndex = ASPxGridView1.EditingRowVisibleIndex;
string rowValue = ASPxGridView1.GetRowValues(editingRowVisibleIndex, "Description").ToString();
string[] rowValueItems = rowValue.Split(';');
List<string> rowValueItemsAsList = new List<string>();
rowValueItemsAsList.AddRange(rowValueItems);
foreach (ListEditItem item in listBox.Items) {
if (rowValueItemsAsList.Contains(item.Value.ToString())) {
item.Selected = true;
}
}
}
protectedvoidASPxGridView1_RowUpdating(object sender, DevExpress.Web.Data.ASPxDataUpdatingEventArgs e) {
var grid = (ASPxGridView)sender;
ASPxListBox listBox = (ASPxListBox)grid.FindEditFormTemplateControl("ASPxListBox1");
string selectedItemsAsString = string.Empty;
foreach (ListEditItem item in listBox.SelectedItems) {
selectedItemsAsString += item.Text + ";";
}
if (selectedItemsAsString.Length > 0) {
selectedItemsAsString = selectedItemsAsString.Trim(';');
}
// e.NewValues["Description"] = selectedItemsAsString; //Uncomment this line to allow editing
}
protectedvoidASPxGridView1_RowValidating(object sender, DevExpress.Web.Data.ASPxDataValidationEventArgs e) {
e.RowError = "Data source modification is not allowed. To test the updating operation, download the project and run it locally";//Remove this line in local environment
}
}
<h1>How to use ASPxListBox inside the EditForm for editing ASPxGridView</h1><dx:ASPxGridViewID="ASPxGridView1"runat="server"AutoGenerateColumns="False"DataSourceID="AccessDataSource1"KeyFieldName="CategoryID"OnRowUpdating="ASPxGridView1_RowUpdating"OnRowValidating="ASPxGridView1_RowValidating"><Columns><dx:GridViewCommandColumnVisibleIndex="0"ShowEditButton="true"></dx:GridViewCommandColumn><dx:GridViewDataTextColumnFieldName="CategoryID"ReadOnly="True"VisibleIndex="0"><EditFormSettingsVisible="False" /></dx:GridViewDataTextColumn><dx:GridViewDataTextColumnFieldName="CategoryName"VisibleIndex="1"></dx:GridViewDataTextColumn><dx:GridViewDataTextColumnFieldName="Description"VisibleIndex="2"></dx:GridViewDataTextColumn></Columns><Templates><EditForm><dx:ASPxListBoxID="ASPxListBox1"runat="server"DataSourceID="AccessDataSource2"SelectionMode="CheckColumn"TextField="ProductName"ValueField="ProductName"ValueType="System.String"OnDataBound="ASPxListBox1_DataBound"></dx:ASPxListBox><br /><dx:ASPxGridViewTemplateReplacementID="btnUpdate"runat="server"ReplacementType="EditFormUpdateButton"></dx:ASPxGridViewTemplateReplacement><dx:ASPxGridViewTemplateReplacementID="btnCancel"runat="server"ReplacementType="EditFormCancelButton"></dx:ASPxGridViewTemplateReplacement></EditForm></Templates></dx:ASPxGridView></div><asp:AccessDataSourceID="AccessDataSource1"runat="server"DataFile="~/App_Data/nwind.mdb"SelectCommand="SELECT [CategoryID], [CategoryName], [Description] FROM [Categories]"DeleteCommand="DELETE FROM [Categories] WHERE [CategoryID] = ?"InsertCommand="INSERT INTO [Categories] ([CategoryID], [CategoryName], [Description]) VALUES (?, ?, ?)"UpdateCommand="UPDATE [Categories] SET [CategoryName] = ?, [Description] = ? WHERE [CategoryID] = ?"><DeleteParameters><asp:ParameterName="CategoryID"Type="Int32" /></DeleteParameters><UpdateParameters><asp:ParameterName="CategoryName"Type="String" /><asp:ParameterName="Description"Type="String" /><asp:ParameterName="CategoryID"Type="Int32" /></UpdateParameters><InsertParameters><asp:ParameterName="CategoryID"Type="Int32" /><asp:ParameterName="CategoryName"Type="String" /><asp:ParameterName="Description"Type="String" /></InsertParameters></asp:AccessDataSource><asp:AccessDataSourceID="AccessDataSource2"runat="server"DataFile="~/App_Data/nwind.mdb"SelectCommand="SELECT [ProductName] FROM [Products]"></asp:AccessDataSource>
ImportsDevExpress.WebPartialPublicClass _Default
Inherits System.Web.UI.Page
ProtectedSub Page_Load(ByVal sender AsObject, ByVal e As EventArgs)
EndSubProtectedSub ASPxListBox1_DataBound(ByVal sender AsObject, ByVal e As EventArgs)
Dim listBox = DirectCast(sender, ASPxListBox)
Dim editingRowVisibleIndex AsInteger = ASPxGridView1.EditingRowVisibleIndex
Dim rowValue AsString = ASPxGridView1.GetRowValues(editingRowVisibleIndex, "Description").ToString()
Dim rowValueItems() AsString = rowValue.Split(";"c)
Dim rowValueItemsAsList AsNew List(OfString)()
rowValueItemsAsList.AddRange(rowValueItems)
ForEach item As ListEditItem In listBox.Items
If rowValueItemsAsList.Contains(item.Value.ToString()) Then
item.Selected = TrueEndIfNext item
EndSubProtectedSub ASPxGridView1_RowUpdating(ByVal sender AsObject, ByVal e As DevExpress.Web.Data.ASPxDataUpdatingEventArgs)
Dim grid = DirectCast(sender, ASPxGridView)
Dim listBox As ASPxListBox = CType(grid.FindEditFormTemplateControl("ASPxListBox1"), ASPxListBox)
Dim selectedItemsAsString AsString = String.Empty
ForEach item As ListEditItem In listBox.SelectedItems
selectedItemsAsString &= item.Text & ";"Next item
If selectedItemsAsString.Length > 0Then
selectedItemsAsString = selectedItemsAsString.Trim(";"c)
EndIf' e.NewValues["Description"] = selectedItemsAsString; //Uncomment this line to allow editing EndSubProtectedSub ASPxGridView1_RowValidating(ByVal sender AsObject, ByVal e As DevExpress.Web.Data.ASPxDataValidationEventArgs)
e.RowError = "Data source modification is not allowed. To test the updating operation, download the project and run it locally"'Remove this line in local environmentEndSubEndClass
The following code snippet (auto-collected from DevExpress Examples) contains a reference to the EditingRowVisibleIndex property.
Note
The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.