Editing in a gridview

T

Tina

I'm in the RowDataBound event for a gridview. my money fields and dates
are in unedited format. The following works fine but is this the easiest
way? Isn't there a way to apply formating to the string without having to
convert the string to its native type and then back to an edited string?

double mydouble = double.Parse(e.Row.Cells[totalcharge].Text);
e.Row.Cells[totalcharge].Text = mydouble.ToString("c");
DateTime myDateTime = DateTime.Parse(e.Row.Cells[designdate].Text);
e.Row.Cells[designdate].Text = myDateTime.ToShortDateString();
Thanks,
T
 
D

dunny

Tina

Unless you have row-specific rules you can avoid RowDataBound
alltogether and change your column defs to something like:

<asp:BoundField DataFormatString="{0:c}" DataField="totalcharge" ...
<asp:BoundField DataFormatString="{0:d}" DataField="designdate"
HtmlEncode="false"...

Remember the HtmlEncode when formatting dates!

Mark
 
T

Tina

my data is created at run time.


dunny said:
Tina

Unless you have row-specific rules you can avoid RowDataBound
alltogether and change your column defs to something like:

<asp:BoundField DataFormatString="{0:c}" DataField="totalcharge" ...
<asp:BoundField DataFormatString="{0:d}" DataField="designdate"
HtmlEncode="false"...

Remember the HtmlEncode when formatting dates!

Mark

I'm in the RowDataBound event for a gridview. my money fields and
dates
are in unedited format. The following works fine but is this the easiest
way? Isn't there a way to apply formating to the string without having
to
convert the string to its native type and then back to an edited string?

double mydouble = double.Parse(e.Row.Cells[totalcharge].Text);
e.Row.Cells[totalcharge].Text = mydouble.ToString("c");
DateTime myDateTime = DateTime.Parse(e.Row.Cells[designdate].Text);
e.Row.Cells[designdate].Text = myDateTime.ToShortDateString();
Thanks,
T
 

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

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top