We’ll it’s been awhile, but I’m back to the ‘art’ of programming in VB.Net / ASP.Net.
Today I was trying to figure out how to set data in a GridView to uppercase. Well, not finding any help out there, I decided to forge my own path. Below is what I’ve discovered.
The first step is to create a function that converts the cells contents into uppercase...
I want to convert the data in the 9th cell (column) – remember the grid cells are zero based, so visually this is the 10th cell (column) – to uppercase
Protected Sub MyGrid_DataBound(ByVal sender As Object, _
ByVal e As GridViewRowEventArgs)
If e.Row.RowType = DataControlRowType.DataRow Then
' Display the cell contents in uppercase
e.Row.Cells(9).Text = e.Row.Cells(9).Text.ToUpper
End If
End Sub
Then add an attribute to the grid’s ASP.Net configuration that calls that function when Row Data is bound to the grid.
Now, whenever a row is bound to the grid using MyGrid.DataBind(), the contents of the 9th column (cell) will be converted to uppercase.
How’s that for simplicity?