Category / Section
how to change the button color in GridDataBoundGrid using QueryCellInfo event?
1 min read
To change the style of a cell or specific cell type you need to use QueryCellInfo event. PrepareViewStyleInfo event can also be used instead of QueryCellInfo.
C#
//Event Handler this.gridDataBoundGrid1.Model.QueryCellInfo += Model_QueryCellInfo; void Model_QueryCellInfo(object sender, GridQueryCellInfoEventArgs e) { if (e.ColIndex == 4 && e.RowIndex > 0) { e.Style.CellType = GridCellTypeName.PushButton; e.Style.HorizontalAlignment = GridHorizontalAlignment.Center; e.Style.VerticalAlignment = GridVerticalAlignment.Middle; e.Style.Description = "Test"; e.Style.TextColor = Color.Red; e.Style.BackColor = Color.AliceBlue; } }
VB
'Event Handler Me.gridDataBoundGrid1.Model.QueryCellInfo void Model_QueryCellInfo(object sender, GridQueryCellInfoEventArgs e) { if (e.ColIndex == 4 && e.RowIndex > 0) { e.Style.CellType = GridCellTypeName.PushButton; e.Style.HorizontalAlignment = GridHorizontalAlignment.Center; e.Style.VerticalAlignment = GridVerticalAlignment.Middle; e.Style.Description = "Test"; e.Style.TextColor = Color.Red; e.Style.BackColor = Color.AliceBlue; } }
Screenshot
Sample Links