可以在gridview中减少Decima值吗 [英] hw can we decrease the decima values in the gridview

查看:60
本文介绍了可以在gridview中减少Decima值吗的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!

我在网格视图中的值为1234.333333344444444555555512

但由于它的外观非常糟糕,因此我需要将值显示为1234.33333334444

谁能帮助我做到这一点..

Hi!

i have values in grid view is 1234.333333344444444555555512

but due to this its look very horrible, so i need to display value as 1234.33333334444

can anyone help me to do this ..

推荐答案

使用DataFormatString属性.
使用''F或f:以固定格式显示数字值.您可以指定小数位数.''.对于六个小数位:
Use DataFormatString property.
Use ''F or f: Displays numeric values in fixed format. You can specify the number of decimal places.''. For six decimal places:
<asp:BoundField DataField="totaldata" HeaderText="Total Data"

     ReadOnly="True" SortExpression="totaldata" DataFormatString="{0:F6}" />



此处的详细信息: BoundField.DataFormatString属性 [ ^ ]


更新:
如果我是正确的话,那么您现在要做的就是将数据表绑定到网格,并放入"AutoGenerateColumns = true".

创建绑定列的意思是,设置AutoGenerateColumns = false,然后在设计器中将这些列定义为绑定列.将列映射到期望的字段.这样做将为您提供格式化列的选项.在此处将DataFormatString用于所需的列.

替代:
如果您不想这样做,那么还有其他选择.您可以从源本身格式化值,也可以在绑定之前格式化值.因此,如果要从数据库获取数据,请以格式化的方式获取数据,以便仅显示3个小数.如果您不愿意在数据库级别执行此操作,则可以在业务逻辑层(如果存在!)中执行此操作.在将表绑定到网格之前,请在数据表行上创建一个foreach循环.对于讨论中的列,获取值并根据需要对其进行修改/更新.循环完成后,您可以使用新的/更新的数据表与网格进行绑定.



Details here: BoundField.DataFormatString Property [^]


UPDATE:
If I am correct, all you are doing right now is binding a datatable to a grid and put ''AutoGenerateColumns=true''.

What I am meant by creating bound column is, set AutoGenerateColumns=false and then define the columns as bound columns in your designer. Map the columns to expected fields. Doing this would give you option to format columns. Use DataFormatString for your desired column here.

Alternative:
In case, you don''t want to do this, then there is other option too. You can format the value from the source itself OR before binding. So, if you are getting the data from DB, get the data in formatted way such that only 3 decimal is shown. If you are hesitant in doing this at DB level then you can do this in your business logic layer (if it exists!). Just before binding the table to grid, create a foreach loop on the datatable rows. For the column in discussion, get the value and modify/update it as per need. Once the loop is done, you can use the new/updated datatable to bind with grid.


这篇关于可以在gridview中减少Decima值吗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆