2

I need to update devexpress gridview data column value automatically if condition is met. I tried to implement it using HtmldatacellPrepared but there is error at line e.GetValue("Status") = "Delay" : Expression is a value and therefore cannot be the target of an assignment. Is there any other method to use to implement this?

Protected Sub Grid_HtmldatacellPrepared(sender As Object, e As ASPxGridViewTableDataCellEventArgs)
if e.GetValue("Forecast") IsNot DBNull.Value Then

  If e.DataColumn.VisibleIndex = 9 Then

     If e.GetValue("Forecast") > Date.Now Then

         e.GetValue("Status") = "Delay"        

     End if

  End If

End If

End Sub
Vanquisher
  • 35
  • 8

2 Answers2

1

Use the ASPxGridView.CustomColumnDisplayText event instead of the ASPxGridView.HtmlDataCellPrepared one, and set the EventArgs e.DisplayText property. Check out my answer here.

Mikhail
  • 9,186
  • 4
  • 33
  • 49
1

e.GetValue("...") is a function so you cannot assign value to it.

I don't have DevExpress component handy to test but based on their online doc, I draft below how to set the cell value.

In order to set the value of the "Status" cell, handle the grid's CustomColumnDisplayText event. Detect if the target cell (i.e "Status") is currently being processed and set the value using e.DisplayText property.

Protected Sub ASPxGridView1_CustomColumnDisplayText(ByVal sender As Object, ByVal e As DevExpress.Web.ASPxGridViewColumnDisplayTextEventArgs) Handles ASPxGridView1.CustomColumnDisplayText
    If e.Column.FieldName = "Status" Then
        Dim grid = DirectCast(sender, ASPxGridView)
        Dim forecast As Object = grid.GetRowValues(e.VisibleRowIndex,"Forecast")

        If forecast IsNot DBNull.Value AndAlso CDate(forecast) > Date.Now Then
            e.DisplayText = "Delay"
        End If 
    End If 
End Sub 

Hopefully that will give you rough idea.

ajakblackgoat
  • 2,119
  • 1
  • 15
  • 10