Back to Devexpress

ASPxGridView.GetRowValuesByKeyValue(Object, String[]) Method

aspnet-devexpress-dot-web-dot-aspxgridview-dot-getrowvaluesbykeyvalue-x28-system-dot-object-system-dot-string-x29.md

latest5.9 KB
Original Source

ASPxGridView.GetRowValuesByKeyValue(Object, String[]) Method

Returns the specified row’s values displayed within the specified columns (fields).

Namespace : DevExpress.Web

Assembly : DevExpress.Web.v25.2.dll

NuGet Package : DevExpress.Web

Declaration

csharp
public object GetRowValuesByKeyValue(
    object keyValue,
    params string[] fieldNames
)
vb
Public Function GetRowValuesByKeyValue(
    keyValue As Object,
    ParamArray fieldNames As String()
) As Object

Parameters

NameTypeDescription
keyValueObject

An object that uniquely identifies the row.

| | fieldNames | String[] |

The names of data source fields whose values are returned.

|

Returns

TypeDescription
Object

An object that contains the row values displayed within the specified columns (fields).

|

Example

The code sample below demonstrates how you can prohibit a user from editing data rows containing information unrelated to the Sales department.

csharp
string UserDepartment = "Sales";
...
protected void MyGridView_StartRowEditing(object sender, DevExpress.Web.Data.ASPxStartRowEditingEventArgs e) {
     if (MyGridView.GetRowValuesByKeyValue(e.EditingKeyValue, "Department").ToString() != UserDepartment) {
          e.Cancel = true;
     }
}
vb
Dim UserDepartment As String = "Sales"
...
Protected Sub MyGridView_StartRowEditing(sender As Object, e As DevExpress.Web.Data.ASPxStartRowEditingEventArgs)
    If MyGridView.GetRowValuesByKeyValue(e.EditingKeyValue, "Department").ToString() <> UserDepartment Then
        e.Cancel = True
    End If
End Sub
aspx
<dx:ASPxGridView ID="MyGridView" runat="server" AutoGenerateColumns="False" DataSourceID="AccessDataSource1"
KeyFieldName="ID" OnStartRowEditing="MyGridView_StartRowEditing">
          <Columns>
          <dx:GridViewCommandColumn VisibleIndex="0">
                    <EditButton Visible="True">
                    </EditButton>
          </dx:GridViewCommandColumn>
          <dx:GridViewDataTextColumn FieldName="Department" ReadOnly="True" VisibleIndex="0">
          </dx:GridViewDataTextColumn>
          ...
          </Columns>
</dx:ASPxGridView>

The following code snippets (auto-collected from DevExpress Examples) contain references to the GetRowValuesByKeyValue(Object, 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.

asp-net-web-forms-grid-initialize-editor-conditionally/CS/WebApplication_Grid/CustomEditItem.aspx.cs#L14

csharp
ASPxGridView grid = (ASPxGridView)sender;
DataType dataType = (DataType)grid.GetRowValuesByKeyValue(e.Keys[0], "Type");

asp-net-web-forms-grid-use-cascading-combo-boxes-in-inline-edit-mode/CS/MultiCombo/Default.aspx.cs#L59

csharp
protected void grid_StartRowEditing(object sender, DevExpress.Web.Data.ASPxStartRowEditingEventArgs e) {
    object[] vals = (object[])grid.GetRowValuesByKeyValue(e.EditingKeyValue,
        new string[] { "Category1ID", "Category2ID", "Category3ID" });

asp-net-web-forms-grid-initialize-editor-conditionally/VB/WebApplication_Grid/CustomEditItem.aspx.vb#L16

vb
Dim grid As ASPxGridView = DirectCast(sender, ASPxGridView)
Dim dataType As DataType = CType(grid.GetRowValuesByKeyValue(e.Keys(0), "Type"), DataType)

asp-net-web-forms-grid-use-cascading-combo-boxes-in-inline-edit-mode/VB/MultiCombo/Default.aspx.vb#L62

vb
Protected Sub grid_StartRowEditing(ByVal sender As Object, ByVal e As DevExpress.Web.Data.ASPxStartRowEditingEventArgs)
    Dim vals() As Object = CType(grid.GetRowValuesByKeyValue(e.EditingKeyValue, New String() { "Category1ID", "Category2ID", "Category3ID" }), Object())
    Session("Cat1ID") = vals(0)

See Also

Online example: How to use a hyperlink whose argument depends on several cell values in the ASPxGridView

Grid View

ASPxGridView Class

ASPxGridView Members

DevExpress.Web Namespace