I have a ButtonColumn in a DataGrid:
<asp:ButtonColumn HeaderText="Edit" ButtonType="PushButton" Text="Edit" />
How do I set it’s CSS class?
The only way I can see to do it, is hooking to the RowDataBound event:
Protected Sub dgSchedule_ItemDataBound(sender As Object, e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles dgSchedule.ItemDataBound
If e.Item.ItemType = ListItemType.Item OrElse e.Item.ItemType = ListItemType.AlternatingItem Then
DirectCast(e.Item.Cells(6).Controls(0), Button).CssClass = "confirmButton"
End If
End Sub
I just feel like there must be a neater way. What happens if I add/remove columns, I’ll have to come back here and remember to change column 6…
I tried using a TemplateColumn and a usual asp:Button – This worked, but then clicking it did not fire the ItemCommand event of the grid which I need to fire.
I have resolved this by using a GridView instead of a DataGrid. Actually not sure why I used a DataGrid in the first place.
This gives an additional property
ControlStyle-CssClasse.g.