Reputation: 1375
I want to perform some simple auto-formatting to the cells in my GridView. So far, I have the following code:
Private Sub gridviewRefreshPanel_RowDataBound( _
ByVal sender As Object, _
ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) _
Handles gridviewRefreshPanel.RowDataBound
Dim readyStatus As String = DataBinder.Eval(e.Row.DataItem, "READY")
Select Case readyStatus
Case "NO"
e.Row.Cells.Item(5).ForeColor = Drawing.Color.Red
e.Row.Cells.Item(5).Font.Bold = True
Case "N/A"
e.Row.Cells.Item(5).ForeColor = Drawing.Color.Goldenrod
e.Row.Cells.Item(5).Font.Bold = True
Case "YES"
e.Row.Cells.Item(5).ForeColor = Drawing.Color.DarkGreen
e.Row.Cells.Item(5).Font.Bold = True
End Select
End Sub
I'd like to refer to the cells by the column name rather than the index. For example, DataRow:
row.Item("ON_TIME")
How do I achieve this with a GridView?
Upvotes: 5
Views: 6573
Reputation: 52241
you can do like.. but this is c# code
DataRow dr = ((DataRowView)e.Row.DataItem).Row;
dr["ColumnName"]
Edit: Put this condition at the top
if (e.Row.RowType == DataControlRowType.DataRow)
Upvotes: 6