![](/img/trans.png)
[英]How to multiply two columns and display that in another column in a gridview using vb.net
[英]VB.Net - How to compare 2 columns in GridView as numbers?
我有一个GridView,我计划根据某些条件在每行中添加不同的颜色。
一种这样的条件是,如果第6列中的数字大于第7列中的数字,则以特定颜色为行着色。
If e.Row.Cells(6).Text > e.Row.Cells(7).Text Then
e.Row.BackColor = ColorTranslator.FromHtml("#FDD533")
Else
但是,当我测试代码时,似乎只有在第6列的最左值大于第7列时才更改颜色,而不管第6列有几百个而第7列有几千个。
我相信原因来自我, If
使用If
语句中的text
。 但是,我认为可以更改的任何数字实例似乎都不适合代码:
If e.Row.Cells(6).Number > e.Row.Cells(7).Number Then
要么
If e.Row.Cells(6).Integer > e.Row.Cells(7).Integer Then
这些例子给我一个信息说
'Number' is not a member of 'System.Web.UI.WebControls.TableCell'
我还能使用什么与当前代码兼容的东西?
我相信您缺少演员表。 我不确定您是只比较整数还是复杂数字 ,如果您不知道我建议您直接将其转换为双精度数 :
If Convert.ToDouble(e.Row.Cells(6).Text) > Convert.ToDouble(e.Row.Cells(7).Text) Then
e.Row.BackColor = ColorTranslator.FromHtml("#FDD533")
Else
Convert.ToDouble会将任何文本转换为数字。
有关投放的更多信息:
https://www.dotnetheaven.com/article/casting-integer-to-long-single-and-double-using-vb.net
如果您可能有一些空值 ,可以使用TryCast :
https://docs.microsoft.com/en-us/dotnet/visual-basic/language-reference/operators/trycast-operator
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.