473,511 Members | 16,260 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Formatting Numbers for a DropDownList

I am using databinding to populate a dropdownlist with numeric values. Some
of the values have more decimal places than others, and I only want the
minimal number of decimal places necessary displayed. The only way I have
found to do this is to use the following for the DataTextFormatString
property:

"{0:0.######}"

This displays what I want for now, but if the number had more that 6 decimal
places, it would not work. Is there any way to have the number of decimal
places determined and displayed automatically? My data is coming from an SQL
Server 2005 database, and the field in question is declared as numeric(7,5).
I realize that this field can never have more than 5 decimal places, but I
would think there would be a more efficient and easier way to say "Only
display the necessary decimal places". Thanks.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/
Sep 26 '07 #1
3 2485
"Nathan Sokalski" <nj********@hotmail.comwrote in message
news:uS**************@TK2MSFTNGP02.phx.gbl...
I realize that this field can never have more than 5 decimal places, but I
would think there would be a more efficient and easier way to say "Only
display the necessary decimal places". Thanks.
..ToString().TrimEnd('0');
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Sep 26 '07 #2
"Nathan Sokalski" <nj********@hotmail.comwrote in message
news:eE**************@TK2MSFTNGP06.phx.gbl...

[cross-posting removed and top-posting corrected]
>.ToString().TrimEnd('0');
That would return the correct value if I were trying to format a String
variable, but I am using DataBinding with a DropDownList. Therefore, the
only means of formatting my text value is to use the DataTextFormatString
property (Obviously I could just loop through the results returned by the
database to use your suggestion, but that is more work and probably less
efficient). The DataTextFormatString uses a FormatString, not String
methods. Any other ideas? Thanks.
If you don't want to use the OnDataBinding event, why not just return the
data from the database in the format that you require it...?
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Sep 27 '07 #3
That would return the correct value if I were trying to format a String
variable, but I am using DataBinding with a DropDownList. Therefore, the
only means of formatting my text value is to use the DataTextFormatString
property (Obviously I could just loop through the results returned by the
database to use your suggestion, but that is more work and probably less
efficient). The DataTextFormatString uses a FormatString, not String
methods. Any other ideas? Thanks.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/

"Mark Rae [MVP]" <ma**@markNOSPAMrae.netwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
"Nathan Sokalski" <nj********@hotmail.comwrote in message
news:uS**************@TK2MSFTNGP02.phx.gbl...
>I realize that this field can never have more than 5 decimal places, but
I would think there would be a more efficient and easier way to say "Only
display the necessary decimal places". Thanks.

.ToString().TrimEnd('0');
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Sep 27 '07 #4

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

Similar topics

4
2066
by: Dave Brydon | last post by:
Access 2003 I have a combo box in my personnel table, which draws its data from a trade code table; the original field in the code table, is numeric, Long Integer, and formatted with 5 zero's . ...
4
2785
by: John Sutor | last post by:
I need some code that, on each keyup event, will take all of the numbers typed into the text box and format as they type to look like this 100 1,000 10,000 100,000 1,000,000 John S
7
398
by: ilona | last post by:
Hi all, I store phone numbers in the database as 123447775665554(input mask is used for input, and some numbers have extensions), and I also know from db if the number is Canadian, US, or some...
0
965
by: George Durzi | last post by:
I have a stored procedure that is returning a column which is cast(company_name as char(30)) + ' | ' + cast(client_name as char(20) + ' | ' 2by4 Brand Architects | Test, TEst ...
1
2073
by: strout | last post by:
I know it's dumb ... sometimes frustrating I want the text and a dropdownlist align with both side of a table cell, i.e. text align left and dropdownlist align right. I cannot add more cells to...
3
2387
by: Nathan Sokalski | last post by:
I want to change the background color, font attributes, etc. of the choices in my DropDownLists. When writing them using HTML SELECT and OPTION tags, I can do something like the following: ...
5
11330
by: Mike P | last post by:
The default format for the DetailsView control is for there to be a row per field. Is it possible set it to show more than one column per row (see below)? ID ... Name ......
4
1205
by: koonda | last post by:
Hi all, I am working on a project. Everything is working fine except the date formating. I have five listboxes and a dropdownlist box controls. The 5 listboxes I have populated from the underlying...
3
1677
by: sparks | last post by:
We have one database that they are constantly reformatting their inputs. I asked about the changes and they can never get the same types of numbers from the people. some are -.95 and later they...
0
7242
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
7353
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,...
1
7075
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...
1
5063
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...
0
4737
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3222
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3212
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1572
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
446
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.