简体   繁体   English

ASP.NET DataGrid-将米格式化为英尺

[英]Asp.net datagrid - format meters to feet

Using asp.net 4.5, I have a gridview bound to a sqlserver table. 使用asp.net 4.5,我有一个绑定到sqlserver表的gridview。

I have a column of type float that contains a distance value in meters. 我有一个float类型的列,其中包含以米为单位的距离值。

However, I'd like to show the value to the user in feet with ft at the end. 但是,我想以英尺为底,以英尺为单位向用户显示该值。

Like: 3.28 ft 赞:3.28 ft

Is there an opportunity to do a complex conversion of what the user sees? 是否有机会对用户看到的内容进行复杂的转换?

Also, if the user types in a value of "3.28 ft" I'd like to convert it into meters and store it into the database. 另外,如果用户输入的值为“ 3.28 ft”,我想将其转换为米并存储到数据库中。 Is this also possible? 这有可能吗?

If either of these are possible, can you point me in the general direction of how this can be done?? 如果这两种方法都可行,您能指出我的大致方向吗?

Thanks! 谢谢!

You can use the CellFormatting and CellParsing events to control the difference between what is shown to the user and what the actual underlying data value is. 您可以使用CellFormatting和CellParsing事件来控制显示给用户的内容和实际的基础数据值之间的差异。 CellFormatting occurs just before the data value is shown and allows you to edit it before it is presented to the user. CellFormatting刚好在显示数据值之前发生,并允许您在将数据显示给用户之前对其进行编辑。 CellParsing occurs just after the user edits the value and allows you to convert the input value from one or more formats back to the original data type. 在用户编辑值之后,CellParsing就会发生,并允许您将输入值从一种或多种格式转换回原始数据类型。

MSDN on CellFormatting MSDN上的CellFormatting
MSDN on CellParsing MSDN上的CellParsing

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM