Format gridview cell in code

J

Jan Erik Hansen

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
 
A

Angel

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top