ASPxGridView.EditingRowVisibleIndex Property
Gets the index of the data row currently being edited.
Namespace: DevExpress.Web
Assembly:
DevExpress.Web.v24.2.dll
Declaration
public int EditingRowVisibleIndex { get; }
Public ReadOnly Property EditingRowVisibleIndex As Integer
Property Value
Type |
Description |
Int32 |
An integer value that identifies the row currently being edited. -1 if no data row is being edited.
|
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.
Example
This example illustrates how to use the ASPxListBox control (ListEditSelectionMode) inside the EditForm for editing ASPxGridView.
View Example
<h1>How to use ASPxListBox inside the EditForm for editing ASPxGridView</h1>
<dx:ASPxGridView ID="ASPxGridView1" runat="server" AutoGenerateColumns="False" DataSourceID="AccessDataSource1"
KeyFieldName="CategoryID" OnRowUpdating="ASPxGridView1_RowUpdating" OnRowValidating="ASPxGridView1_RowValidating">
<Columns>
<dx:GridViewCommandColumn VisibleIndex="0" ShowEditButton="true">
</dx:GridViewCommandColumn>
<dx:GridViewDataTextColumn FieldName="CategoryID" ReadOnly="True" VisibleIndex="0">
<EditFormSettings Visible="False" />
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn FieldName="CategoryName" VisibleIndex="1">
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn FieldName="Description" VisibleIndex="2">
</dx:GridViewDataTextColumn>
</Columns>
<Templates>
<EditForm>
<dx:ASPxListBox ID="ASPxListBox1" runat="server" DataSourceID="AccessDataSource2"
SelectionMode="CheckColumn" TextField="ProductName" ValueField="ProductName" ValueType="System.String" OnDataBound="ASPxListBox1_DataBound">
</dx:ASPxListBox>
<br />
<dx:ASPxGridViewTemplateReplacement ID="btnUpdate" runat="server" ReplacementType="EditFormUpdateButton"></dx:ASPxGridViewTemplateReplacement>
<dx:ASPxGridViewTemplateReplacement ID="btnCancel" runat="server" ReplacementType="EditFormCancelButton"></dx:ASPxGridViewTemplateReplacement>
</EditForm>
</Templates>
</dx:ASPxGridView>
</div>
<asp:AccessDataSource ID="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:Parameter Name="CategoryID" Type="Int32" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="CategoryName" Type="String" />
<asp:Parameter Name="Description" Type="String" />
<asp:Parameter Name="CategoryID" Type="Int32" />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Name="CategoryID" Type="Int32" />
<asp:Parameter Name="CategoryName" Type="String" />
<asp:Parameter Name="Description" Type="String" />
</InsertParameters>
</asp:AccessDataSource>
<asp:AccessDataSource ID="AccessDataSource2" runat="server" DataFile="~/App_Data/nwind.mdb"
SelectCommand="SELECT [ProductName] FROM [Products]"></asp:AccessDataSource>
using DevExpress.Web;
public partial class _Default : System.Web.UI.Page {
protected void Page_Load(object sender, EventArgs e) {
}
protected void ASPxListBox1_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;
}
}
}
protected void ASPxGridView1_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
}
protected void ASPxGridView1_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:ASPxGridView ID="ASPxGridView1" runat="server" AutoGenerateColumns="False" DataSourceID="AccessDataSource1"
KeyFieldName="CategoryID" OnRowUpdating="ASPxGridView1_RowUpdating" OnRowValidating="ASPxGridView1_RowValidating">
<Columns>
<dx:GridViewCommandColumn VisibleIndex="0" ShowEditButton="true">
</dx:GridViewCommandColumn>
<dx:GridViewDataTextColumn FieldName="CategoryID" ReadOnly="True" VisibleIndex="0">
<EditFormSettings Visible="False" />
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn FieldName="CategoryName" VisibleIndex="1">
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn FieldName="Description" VisibleIndex="2">
</dx:GridViewDataTextColumn>
</Columns>
<Templates>
<EditForm>
<dx:ASPxListBox ID="ASPxListBox1" runat="server" DataSourceID="AccessDataSource2"
SelectionMode="CheckColumn" TextField="ProductName" ValueField="ProductName" ValueType="System.String" OnDataBound="ASPxListBox1_DataBound">
</dx:ASPxListBox>
<br />
<dx:ASPxGridViewTemplateReplacement ID="btnUpdate" runat="server" ReplacementType="EditFormUpdateButton"></dx:ASPxGridViewTemplateReplacement>
<dx:ASPxGridViewTemplateReplacement ID="btnCancel" runat="server" ReplacementType="EditFormCancelButton"></dx:ASPxGridViewTemplateReplacement>
</EditForm>
</Templates>
</dx:ASPxGridView>
</div>
<asp:AccessDataSource ID="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:Parameter Name="CategoryID" Type="Int32" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="CategoryName" Type="String" />
<asp:Parameter Name="Description" Type="String" />
<asp:Parameter Name="CategoryID" Type="Int32" />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Name="CategoryID" Type="Int32" />
<asp:Parameter Name="CategoryName" Type="String" />
<asp:Parameter Name="Description" Type="String" />
</InsertParameters>
</asp:AccessDataSource>
<asp:AccessDataSource ID="AccessDataSource2" runat="server" DataFile="~/App_Data/nwind.mdb"
SelectCommand="SELECT [ProductName] FROM [Products]"></asp:AccessDataSource>
Imports DevExpress.Web
Partial Public Class _Default
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
End Sub
Protected Sub ASPxListBox1_DataBound(ByVal sender As Object, ByVal e As EventArgs)
Dim listBox = DirectCast(sender, ASPxListBox)
Dim editingRowVisibleIndex As Integer = ASPxGridView1.EditingRowVisibleIndex
Dim rowValue As String = ASPxGridView1.GetRowValues(editingRowVisibleIndex, "Description").ToString()
Dim rowValueItems() As String = rowValue.Split(";"c)
Dim rowValueItemsAsList As New List(Of String)()
rowValueItemsAsList.AddRange(rowValueItems)
For Each item As ListEditItem In listBox.Items
If rowValueItemsAsList.Contains(item.Value.ToString()) Then
item.Selected = True
End If
Next item
End Sub
Protected Sub ASPxGridView1_RowUpdating(ByVal sender As Object, ByVal e As DevExpress.Web.Data.ASPxDataUpdatingEventArgs)
Dim grid = DirectCast(sender, ASPxGridView)
Dim listBox As ASPxListBox = CType(grid.FindEditFormTemplateControl("ASPxListBox1"), ASPxListBox)
Dim selectedItemsAsString As String = String.Empty
For Each item As ListEditItem In listBox.SelectedItems
selectedItemsAsString &= item.Text & ";"
Next item
If selectedItemsAsString.Length > 0 Then
selectedItemsAsString = selectedItemsAsString.Trim(";"c)
End If
' e.NewValues["Description"] = selectedItemsAsString; //Uncomment this line to allow editing
End Sub
Protected Sub ASPxGridView1_RowValidating(ByVal sender As Object, 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 environment
End Sub
End Class
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.
See Also