Skip to main content
Tab

ASPxGridView.FocusedRowIndex Property

Gets or sets the focused row by its index.

Namespace: DevExpress.Web

Assembly: DevExpress.Web.v22.1.dll

Declaration

public int FocusedRowIndex { get; set; }

Property Value

Type Description
Int32

An integer value that specifies the focused row’s index.

Remarks

Rows within a Grid View are identified by their indexes. The FocusedRowIndex property identifies the currently focused row. Setting this property to a new value moves focus to the corresponding row displayed within the current page.

If the row isn’t displayed within the current page, you should switch to the required page and then move row focus (see an example below).

When row focus changes, the ASPxGridView.FocusedRowChanged event is raised.

The focused row feature is enabled when the ASPxGridViewBehaviorSettings.AllowFocusedRow property is set to true. Otherwise, the FocusedRowIndex property’s value is set to -1. In this instance, the row currently being edited is identified by the ASPxGridView.EditingRowVisibleIndex property.

Example

The following example illustrates how to use the FocusedRowIndex property.

Web Forms approach:

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 approach:

@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

See Also