473,396 Members | 2,013 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,396 software developers and data experts.

dataset/GridView calculation

I have a dataset that is populating my gridview, but I have a data in the
dataset coming out like .011 and showing in the gridView as .011%. I need to
calculate that so it shows as 1.1% and not .011%. How can I do that and still
bind it to my gridView without having to make that calculation on the
database side?

Oct 13 '06 #1
6 3717
Text='<%# convert.toDouble(Eval("myValue")) * 100 %>'

--

Bruno Alexandre
København, Danmark

"a Portuguese in Denmark"

Blog. http://balexandre.blogspot.com/
Photos. http://www.flickr.com/photos/balexandre/
"igotyourdotnet" <ig************@nospam.nospamwrote in message
news:92**********************************@microsof t.com...
>I have a dataset that is populating my gridview, but I have a data in the
dataset coming out like .011 and showing in the gridView as .011%. I need
to
calculate that so it shows as 1.1% and not .011%. How can I do that and
still
bind it to my gridView without having to make that calculation on the
database side?

Oct 13 '06 #2
that didn't work, I'm still getting:
..011 and not 1.1%

I have this
<ItemTemplateField>
<asp:Label runat=server text='<%#Convert.ToDouble(Eval("value")) * 100
%>'></asp:Label>
</ItemTemplateField>
and its showing in my gridView as .011 still.
"Bruno Alexandre" wrote:
Text='<%# convert.toDouble(Eval("myValue")) * 100 %>'

--

Bruno Alexandre
København, Danmark

"a Portuguese in Denmark"

Blog. http://balexandre.blogspot.com/
Photos. http://www.flickr.com/photos/balexandre/
"igotyourdotnet" <ig************@nospam.nospamwrote in message
news:92**********************************@microsof t.com...
I have a dataset that is populating my gridview, but I have a data in the
dataset coming out like .011 and showing in the gridView as .011%. I need
to
calculate that so it shows as 1.1% and not .011%. How can I do that and
still
bind it to my gridView without having to make that calculation on the
database side?


Oct 13 '06 #3
Hi,

I tried that using Northwind Access database, and it seems the expression
should work. What's the data type of underlyiny field in the DataSet?

Also, actually you don't need to do that convert by hand, GridView has a
DataFormatString that can do that for you:

<asp:BoundField DataField="UnitPrice" DataFormatString="{0:P2}"
HtmlEncode="false" />

Sincerely,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications. If you are using Outlook Express, please make sure you clear the
check box "Tools/Options/Read: Get 300 headers at a time" to see your reply
promptly.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Oct 14 '06 #4
its a calculation coming from the stored procedure.
Also, I did the expression in a template field, so how will
asp:BoundField DataField="UnitPrice" DataFormatString="{0:P2}"
HtmlEncode="false" /- this work in a templateField?

I'm using this on other values in the grid but their not templateFields

"Walter Wang [MSFT]" wrote:
Hi,

I tried that using Northwind Access database, and it seems the expression
should work. What's the data type of underlyiny field in the DataSet?

Also, actually you don't need to do that convert by hand, GridView has a
DataFormatString that can do that for you:

<asp:BoundField DataField="UnitPrice" DataFormatString="{0:P2}"
HtmlEncode="false" />

Sincerely,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications. If you are using Outlook Express, please make sure you clear the
check box "Tools/Options/Read: Get 300 headers at a time" to see your reply
promptly.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Oct 16 '06 #5
Hi,

Sorry for late reply.

For TemplateField, when using Eval or Bind to get the bound data, it can
use another parameter to specify a format string:

<ItemTemplate>
<asp:Label runat="server" ID="lbl1" Text='<%# Eval("value", "{0:P2}")
%>'></asp:Label>
</ItemTemplate>

However, after I reviewed your question again, I suspect it might still not
work for your case. Since using your "Convert.ToDouble" code on my side
will work correctly, I think it might be related to the data type of the
field "value" in your DataSet.

I've done following test using a VARCHAR field:

1) If I use DataFormatString or Eval/Bind with format string "{0:P2}", it
will not work, it will still display "0.011".

2) If I use your original code 'Convert.ToDouble("value")) * 100', it
should display "1.1" instead.

Is it possible for you to create a small reproducible project to show this
issue? I will have to have such a project to find the root cause of this
issue. Thank you for your effort and understanding.

Regards,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
Oct 18 '06 #6
I got this to work actually. I created a variable in the code behind and
bound that to my grid.

"igotyourdotnet" <ig************@nospam.nospamwrote in message
news:17**********************************@microsof t.com...
its a calculation coming from the stored procedure.
Also, I did the expression in a template field, so how will
asp:BoundField DataField="UnitPrice" DataFormatString="{0:P2}"
HtmlEncode="false" /- this work in a templateField?

I'm using this on other values in the grid but their not templateFields

"Walter Wang [MSFT]" wrote:
>Hi,

I tried that using Northwind Access database, and it seems the expression
should work. What's the data type of underlyiny field in the DataSet?

Also, actually you don't need to do that convert by hand, GridView has a
DataFormatString that can do that for you:

<asp:BoundField DataField="UnitPrice" DataFormatString="{0:P2}"
HtmlEncode="false" />

Sincerely,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

================================================= =
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications. If you are using Outlook Express, please make sure you clear
the
check box "Tools/Options/Read: Get 300 headers at a time" to see your
reply
promptly.

Note: The MSDN Managed Newsgroup support offering is for non-urgent
issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each
follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
================================================= =

This posting is provided "AS IS" with no warranties, and confers no
rights.


Oct 19 '06 #7

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

Similar topics

2
by: David R. | last post by:
I would like to consume a web service. There is one method in this webservice that returns the results in a DataSet type. I know that I can return the data in a GridView control. However, if I...
1
by: SomebodyElse | last post by:
Hi. Apologies if this has been asked here before - I've searched & searched but can't find anything. It's probably my serach parameters, but I'm having trouble even describing it to a search...
2
by: Stephen | last post by:
Hi, Suppose there is a column in the dataset that is a very large field (say varchar(500)) and i want to display partial information with (....) so that the user can click on it to view for...
3
by: BartMan | last post by:
Greetings, I have a gridview which is sitting on a multi view control (witin a view), and it is bound to a dataset which I dynamically apply to the control within asp.net page. The problem is...
4
by: Justin | last post by:
I'm just learning ASP.NET 2.0 and everything I find on Datasets including the MSPress book I bought go way to far for what I need. I do not need to bind a datasource. My source will be a text...
1
by: rn5a | last post by:
I was using a DataView to bind records from a DB table to a DataGrid using the following code: Dim sqlDapter As SqlDataAdapter Dim dSet As DataSet Dim dView As DataView sqlDapter = New...
0
by: Adam Sandler | last post by:
Hello, Prior to posting I looked at http://groups.google.com/group/ microsoft.public.dotnet.framework.aspnet/browse_thread/thread/ d8d5ae243614085e/d4fd6c4a5aa56f75 ...
0
parshupooja
by: parshupooja | last post by:
Hi all, I need help. I am using asp.net C# . I have binded gridview with 5 columns. I have Dropdownlist in 4 columns Morning in, morning out, afternoon in and afternoon out and label in 5 column...
3
by: ASPnewb1 | last post by:
I am currently filling a dataTable then adding this table to a dataset, setting the dataset to the Gridview's datasource. If I set the Gridview to generate columns automatically it will fill the...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.