![](/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.