Groups | Blog | Home
all groups > dotnet general > january 2008 >

dotnet general : Format gridview cell in code


Jan Erik Hansen
1/31/2008 3:08:30 PM
I have a gridview that I will output to an email.

I try to format a certain cell but it doesn't seem to have any effect,
Can I set the htmlencode for a bound column = false in code?


I have this code:

Dim myGrid As New GridView

myGrid.DataSource = cart_ds

myGrid.DataBind()

'Formatering

myGrid.BackColor = Drawing.Color.LemonChiffon

Dim ii As Integer

For ii = 0 To myGrid.Rows.Count - 1

If myGrid.Rows(ii).RowType = DataControlRowType.DataRow Then

myGrid.Rows(ii).Cells(1).Text = String.Format("{0:c}",
myGrid.Rows(ii).Cells(1).Text)

End If

Next

myGrid.RenderControl(htmlTW)



regards

Jan Erik Hansen



Oslo

Angel
2/1/2008 1:40:56 PM
Just a hint... What ever you are attempting to format must be a datatype
other than a string. If you try something like
Dim x as string ="1900.00"
dim y as string = Format(x, "#,##0.00")

This will not work! instead do this

Dim x as decimal = 1900.00
dim y as string = Format(x, "#,##0.00")

So the moral of the story is make sure that column datatype is something
other than string and it will work. You still need HTLMEncode set to false.

Hope this helps
--
aaa


[quoted text, click to view]
AddThis Social Bookmark Button