Skip to main content
A newer version of this page is available. .
Tab

ASPxGridView.GetRowValues(Int32, String[]) Method

Returns the values of the specified data source fields in the specified row.

Namespace: DevExpress.Web

Assembly: DevExpress.Web.v18.2.dll

Declaration

public object GetRowValues(
    int visibleIndex,
    params string[] fieldNames
)

Parameters

Name Type Description
visibleIndex Int32

Identifies the data row.

fieldNames String[]

An array of the data source field names whose values in the specified row are returned.

Returns

Type Description
Object

An array of field values (if several field names are passed via the fieldNames parameter) or a direct field value (if a single field name is passed via the fieldNames parameter).

Remarks

The GetRowValues method returns the values of the specified data source fields in the specified grid data row.

To work correctly, the GetRowValues method needs the grid to be data bound to its data source. If you call the GetRowValues method in code behind, it returns row values. First, the grid searches for a value in Row Cache. If row data is found, data binding does not occur. If data is not found, the grid is bound with a data source. Refer to the ASPxGridView Row Cache KB article for more information about general aspects of ASPxGridView Row Cache operation (starting from v2011 vol. 2).

The following code snippet illustrates how to get values of several columns simultaneously.


string[] fields = {"FieldName1", "FieldName2", "FieldName3", "FieldName4", "FieldName5"};
object[] values = grid.GetRowValues(3, fields) as object[];
DateTime prog1 = (DateTime)values[4];

Note

If you call the GetRowValues method while an unbound grid control builds its hierarchy (for example, within the ASPxGridView.HtmlRowCreated, ASPxGridView.CustomButtonInitialize or ContextMenuItemVisibility event handlers), the GetRowValues method rebinds to data to reset the hierarchy. It might result in displaying the grid with empty data and losing values entered by an end user. To avoid this behavior, call the grid’s ASPxWebControl.DataBind method within the Page_Load event handler.

Example

List<Record> list = new List<Record>();
protected void Page_Load(object sender, EventArgs e) {
    int start = ASPxGridView1.PageIndex * ASPxGridView1.SettingsPager.PageSize;
    int end = (ASPxGridView1.PageIndex + 1) * ASPxGridView1.SettingsPager.PageSize;
    GridViewDataColumn column1 = ASPxGridView1.Columns["CategoryName"] as GridViewDataColumn;
    GridViewDataColumn column2 = ASPxGridView1.Columns["Description"] as GridViewDataColumn;
    for (int i = start; i < end; i++) {
        ASPxTextBox txtBox1 = (ASPxTextBox)ASPxGridView1.FindRowCellTemplateControl(i, column1, "txtBox");
        ASPxTextBox txtBox2 = (ASPxTextBox)ASPxGridView1.FindRowCellTemplateControl(i, column2, "txtBox");
        if (txtBox1 == null || txtBox2 == null)
            continue;
        int id = Convert.ToInt32(ASPxGridView1.GetRowValues(i, ASPxGridView1.KeyFieldName));
        list.Add(new Record(id, txtBox1.Text, txtBox2.Text));
    }
}

The following code snippets (auto-collected from DevExpress Examples) contain references to the GetRowValues(Int32, String[]) method.

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