473,398 Members | 2,389 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Format gridview cell in code

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
Jan 31 '08 #1
1 5551
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
Feb 1 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: John_H | last post by:
Re: ASP.NET 2.0 I would like suggestions or code examples on how to collect a variable length list of input data (item# & item quantity specifically). I thought that I could accomplish this...
10
by: NH | last post by:
I have a girdview with paging enabled. How can I add a message in the footer to say "Viewing records 1-15 of 45" etc Thanks
0
by: Innova | last post by:
Hi, We are working on a gridview inside the gridview (parent-child) scenario. The data of child grid will depend on the data of parent. Objectives: 1.Add new row in parent grid after each row...
7
by: aljamala | last post by:
Hi, I was wondering if there is a way to make a single cell readonly within a GridView? I know you can do it for a column but what about a cell within that column? Thanks!
3
by: =?Utf-8?B?bmt3?= | last post by:
I have a gridview which need to filled by various data according to user's action. I want to format the dynamical displayed data. For example the number should be right aligned, datetime column...
3
by: Bill Gower | last post by:
I have an cell which contains a field member which is filled with String.Empty. When I retrieve the value in the cell with Cells.Text.ToString() and try to compare it to String.Empty, I can't...
1
Frinavale
by: Frinavale | last post by:
I'm working on an ASP.NET application using VB.NET for server side code. I have a GridView listing a bunch of stuff. Above the GridView I have a checkbox named "ChkBx_SelectAll". If this...
4
by: foolmelon | last post by:
Before AJAX, we were able to focus a cell in a gridview during a fullpage postback. After putting the gridview inside an UpdatePanel, we cannot focus a cell in this gridview anymore. Does anybody...
4
by: =?Utf-8?B?ZGNoMw==?= | last post by:
Is there a way to conditionally format a dateTime field to produce on result if the value is 10/31/2008 12:00 AM (user didn't enter a time) and another result if the value is 10/31/2008 5:30 PM...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.