Skip to main content
Tab

ASPxGridView.FocusedRowIndex Property

Specifies the index of the focused row.

Namespace: DevExpress.Web

Assembly: DevExpress.Web.v23.2.dll

NuGet Package: DevExpress.Web

Declaration

public int FocusedRowIndex { get; set; }

Property Value

Type Description
Int32

The focused row index.

Remarks

ASPxGridView identifies rows by their indices. The FocusedRowIndex property specifies the index of the focused row.

Set the AllowFocusedRow property to true to enable row focus. Change the FocusRowIndex property value to move focus to the corresponding row within the current page. When the row focus changes, the server-side ASPxGridView.FocusedRowChanged or the client-side ASPxClientGridView.FocusedRowChanged event fires (based on the ProcessFocusedRowChangedOnServer property value). If you navigate to another page, the row loses focus.

When row focus is disabled, the FocusedRowIndex property returns -1. To identify the row being edited, use the EditingRowVisibleIndex property.

Web Forms Example

The following example shows how to use the FocusedRowIndex property:

<dx:ASPxGridView ID="gridView" runat="server" AutoGenerateColumns="False" KeyFieldName="CategoryID"
    OnDataBound="gridView_DataBound" OnFocusedRowChanged="gridView_FocusedRowChanged">
    <SettingsBehavior AllowFocusedRow="true" ProcessFocusedRowChangedOnServer="true" />
    <Columns>
        <dx:GridViewDataTextColumn FieldName="CategoryID" ReadOnly="True" VisibleIndex="0">
            <EditFormSettings Visible="False" />
        </dx:GridViewDataTextColumn>
        <dx:GridViewDataTextColumn FieldName="CategoryName" VisibleIndex="1" />
        <dx:GridViewDataTextColumn FieldName="Description" VisibleIndex="2" />
    </Columns>
</dx:ASPxGridView>
protected void gridView_FocusedRowChanged(object sender, EventArgs e) {
    ASPxGridView grid = sender as ASPxGridView;
    Response.Cookies[grid.ID]["FocusedIndex"] = grid.FocusedRowIndex.ToString();
    Response.Cookies[grid.ID].Expires = DateTime.Now.AddDays(1d);
}
protected void gridView_DataBound(object sender, EventArgs e) {
    ASPxGridView grid = sender as ASPxGridView;
    if(!IsPostBack)
    if (Request.Cookies[grid.ID] != null)
        grid.FocusedRowIndex =Convert.ToInt32(Request.Cookies[grid.ID]["FocusedIndex"]);
}

MVC Example

@Html.DevExpress().GridView(settings => {
    settings.Name = "GridView";
    settings.CallbackRouteValues = new { Controller = "Home", Action = "GridViewPartial" };
    settings.SettingsPager.PageSize = 5;

    settings.KeyFieldName = "EmployeeID";
    settings.Columns.Add("LastName");
    settings.Columns.Add("FirstName");
    settings.Columns.Add("City");
    settings.Columns.Add("Country");

    settings.PreRender = (s, e) => {
        var sender = (MVCxGridView)s;
        // Set the zero-based index of the focused row.  
        sender.FocusedRowIndex = 6;
    };
    // Enable row focus.  
    settings.SettingsBehavior.AllowFocusedRow = true;
}).Bind(Model).GetHtml()

Online Examples

View Example: Grid View for ASP.NET Web Forms - How to focus the newly inserted row

View Example: Grid View for ASP.NET MVC - How to focus the newly inserted row

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the FocusedRowIndex 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