简体   繁体   English

带字符串的Concat十进制值

[英]Concat decimal value with string

I am retrieving data from the database and displaying in Gridview. 我正在从数据库中检索数据并显示在Gridview中。 I have some data in which I want to display % sign at the end (in gridview) what would be the best way to achieve this. 我有一些数据想要在结尾(在gridview中)显示%符号,这是实现此目的的最佳方法。 Can I concat % sign in sql select statement or I have to add using vb code behind. 我可以在SQL select语句中连接%登录,还是必须在后面使用vb代码添加。

在此处输入图片说明

The best way is to use DataFormatString property from the Gridview columns and set it to something like "{0:0.00}%". 最好的方法是使用Gridview列中的DataFormatString属性并将其设置为“ {0:0.00}%”。 This will format your results by using the number, 2 decimal positions and adding the % symbol to the end. 这将通过使用数字,两个小数位并在末尾添加%符号来格式化结果。

If you have rows with numeric values and rows that already contain % or other special characters, the best way to assure that the data is correctly visualized would be to remove the % or special characters before setting the Gridview data source. 如果您具有带有数字值的行以及已经包含%或其他特殊字符的行,则确保数据正确可视化的最佳方法是在设置Gridview数据源之前删除%或特殊字符。 This way you will allways get the same result for each row. 这样,您将始终为每一行获得相同的结果。

I loop through the Gridview row and concat % sing at the end 我遍历Gridview行并最后连接%sing

 If e.Row.RowType = DataControlRowType.DataRow Then

            If e.Row.Cells(6).Text = 4 Then
                e.Row.Cells(5).Text += " %"
            End If
        End If

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

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