Format gridview cell in code
am 31.01.2008 15:08:30 von 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
RE: Format gridview cell in code
am 01.02.2008 22:40:56 von rodoopus
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
"Jan Erik Hansen" wrote:
> 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
>
>
>