sah18
asked on
How to format a decimal data type (SQL Server 2000) when displayed (in datagrid)
I have field that is decimal datatype (10,4). Currently, when a number such as 3.25 is entered, it shows up as 3.2500 (after it is saved to the db and retrieved again). And whole numbers, such as 44, show up as 44.0000. I would like to have have the zeros show up at the right of the numbers. Is there a format that will do this? So, for 44, I really do want just 44 to show up. And for 3.25, I really want just 3.25 to show up.
Thank you!
Thank you!
You will want to use the DataFormatString option the DataGrid...
Try.... dataformatstring="{0:D2}"
Try.... dataformatstring="{0:D2}"
ASKER
I'm just not seeing this as an option. I only see it as an option for the BoundColumns. Where should I place this setting?
Since you are using template column, Modify DataBinder.Eval like following:
<%# DataBinder.Eval(Container. DataItem, "dosemg", "{0:D2}") %>
-tushar
<%# DataBinder.Eval(Container.
-tushar
I didn't see your second post until after mine had submitted....
On a textbox I would only know how to do it using the OnItemDataBound event.
There you can access the textbox value and change it as required.
Hopefully someone else knows an easier way?
On a textbox I would only know how to do it using the OnItemDataBound event.
There you can access the textbox value and change it as required.
Hopefully someone else knows an easier way?
Hah there you go :)
** you'll need to modify like following.. D2 works only with integer..
<%# DataBinder.Eval(Container. DataItem, "dosemg", "{0:N2}") %>
here's other list: http://msdn2.microsoft.com/en-US/library/31723w77(VS.80).aspx
<%# DataBinder.Eval(Container.
here's other list: http://msdn2.microsoft.com/en-US/library/31723w77(VS.80).aspx
ASKER
tusharashah - this is getting closer to what I want, but isn't quite it!
now, i see 35.00 when I want to see 35
is there a way for it not to buffer with the trailing zeros at all?
and I don't want to truncate what has been entered at all, just display it without any extra zeros on the right.
so: 123.4567, I would still want to be displayed as 123.4567
but: 123.9000, I would want to be displayed as 123.9
do you know what i mean?
thank you again for your time!!
now, i see 35.00 when I want to see 35
is there a way for it not to buffer with the trailing zeros at all?
and I don't want to truncate what has been entered at all, just display it without any extra zeros on the right.
so: 123.4567, I would still want to be displayed as 123.4567
but: 123.9000, I would want to be displayed as 123.9
do you know what i mean?
thank you again for your time!!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you so much!
ASKER
<asp:TemplateColumn HeaderText="Dose">
<ItemTemplate>
<%# DataBinder.Eval(Container.
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox Width="50px" ID="dosemg" Runat=server Text='<%# DataBinder.Eval(Container.
<asp:requiredfieldvalidato
Display="Dynamic" ErrorMessage="=" ControlToValidate="dosemg"
</EditItemTemplate>
</asp:TemplateColumn>
So, I guess I need to somehow modify
<%# DataBinder.Eval(Container.
to have the format I want in both the ItemTemplate and also the EditItemTemplate.
Any suggestions??
Thanks for your help!