Skip to main content

ASPxGridView.FocusedRowIndex Property

Specifies the index of the focused row.

Namespace: DevExpress.Web

Assembly: DevExpress.Web.v23.1.dll

NuGet Package: DevExpress.Web


public int FocusedRowIndex { get; set; }

Property Value

Type Description

The focused row index.


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" />
        <dx:GridViewDataTextColumn FieldName="CategoryID" ReadOnly="True" VisibleIndex="0">
            <EditFormSettings Visible="False" />
        <dx:GridViewDataTextColumn FieldName="CategoryName" VisibleIndex="1" />
        <dx:GridViewDataTextColumn FieldName="Description" VisibleIndex="2" />
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 (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.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;

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

See Also