2017-08-31 62 views
0

試圖將其轉換爲十進制給出錯誤 是gridview的從字符串「」轉換爲輸入「小數」無效。 - VB

e.Row.Cells(i).Text = If(CType(e.Row.Cells(total).Text, Decimal) = 0, "-", (CType(e.Row.Cells(total).Text, Decimal) * 100/CType(e.Row.Cells(total).Text, Decimal)).ToString("0.00") + "%") 
+0

的行單元格請幫助! TXXX –

+0

嘗試使用TryCast代替CType – N1gthm4r3

+0

它給出--Error 'TryCast'操作數必須是引用類型,但'Decimal'是值類型。 –

回答

1
Dim temp As Decimal 
temp=0 
IF Decimal.TryParse(e.Row.Cells(total).Text, temp) THEN 
e.Row.Cells(i).Text = If(temp = 0, "-", (temp * 100/temp).ToString("0.00") + "%") 
ELSE e.Row.Cells(i).Text = "-" 
+0

「出」不工作 –

+0

@StavanShah而不是他在哪裏'出小數'切換到'臨時'我認爲他只是有點混合起來:) – Jaxi

+0

這段代碼缺少'如果結束'並且不會編譯。 –

相關問題