Back to Devexpress

ASPxGridView.FocusedRowChanged Event

aspnet-devexpress-dot-web-dot-aspxgridview-adf58674.md

latest3.5 KB
Original Source

ASPxGridView.FocusedRowChanged Event

Fires when the row focus changes.

Namespace : DevExpress.Web

Assembly : DevExpress.Web.v25.2.dll

NuGet Package : DevExpress.Web

Declaration

csharp
public event EventHandler FocusedRowChanged
vb
Public Event FocusedRowChanged As EventHandler

Event Data

The FocusedRowChanged event's data class is EventArgs.

Remarks

Set the ProcessFocusedRowChangedOnServer property to true to allow the control to fire the server-side FocusedRowChanged event.

The FocusedRowChanged event fires in the following cases:

If the ProcessFocusedRowChangedOnServer property is set to false, the control raises the client-side ASPxClientGridView.FocusedRowChanged event.

Example

In the example below, the control raises the FocusedRowChanged event to save and restore the focused row index on the server side.

aspx
<dx:ASPxGridView ID="gridView" runat="server" AutoGenerateColumns="False"
    OnDataBound="gridView_DataBound" OnFocusedRowChanged="gridView_FocusedRowChanged">
    <SettingsBehavior AllowFocusedRow="true" ProcessFocusedRowChangedOnServer="true" />
    <Columns>
        <%--...--%>
    </Columns>
</dx:ASPxGridView>
csharp
protected void gridView_FocusedRowChanged(object sender, EventArgs e) {
    ASPxGridView grid = sender as ASPxGridView;
    Response.Cookies[grid.ID]["FocudedIndex"] = 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]["FocudedIndex"]);
}
vb
Protected Sub gridView_FocusedRowChanged(ByVal sender As Object, ByVal e As EventArgs)
    Dim grid As ASPxGridView = TryCast(sender, ASPxGridView)
    Response.Cookies(grid.ID)("FocudedIndex") = grid.FocusedRowIndex.ToString()
    Response.Cookies(grid.ID).Expires = DateTime.Now.AddDays(1R)
End Sub
Protected Sub gridView_DataBound(ByVal sender As Object, ByVal e As EventArgs)
    Dim grid As ASPxGridView = TryCast(sender, ASPxGridView)
    If (Not IsPostBack) Then
    If Request.Cookies(grid.ID) IsNot Nothing Then
        grid.FocusedRowIndex = Convert.ToInt32(Request.Cookies(grid.ID)("FocudedIndex"))
    End If
    End If
End Sub

See Also

ASPxGridView Class

ASPxGridView Members

DevExpress.Web Namespace