Blog Stats
  • Posts - 4
  • Articles - 0
  • Comments - 6
  • Trackbacks - 4

 

GridView Uppercase Formatting

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?

Feedback

# re: GridView Uppercase Formatting

Gravatar THANK YOU THANK YOU THANK YOU!

Oh my god I was pulling my hair out looking for this solution and I couldnt get it to work with what I was using.

I just cut/pasted your code (changed a little) and its doing EXACTLY what I wanted!

Thank you!
Euan 11/30/2005 9:16 PM | Euan

# re: GridView Uppercase Formatting

Gravatar Glad to see this was of help to someone other than me. Isn't the internet great? 1/20/2006 9:03 PM | Mark Pritchard

# re: GridView Uppercase Formatting

Gravatar I agree with Euan. I have been searching through help files and books for hours trying to find the exact property I needed and your post told me in plain english exactly what to do.

THANKS! 6/1/2006 6:55 PM | Jonathan Siemasko

Post a comment





 

 

 

Copyright © Mark Pritchard