开发者

Preventing cast errors

开发者 https://www.devze.com 2022-12-13 11:15 出处:网络
I would like to correctly cast a value in a grid to an integer. The problem is that the value in the grid can sometimes be equal to an empty string which will cause a cast error. Is there a sophistica

I would like to correctly cast a value in a grid to an integer. The problem is that the value in the grid can sometimes be equal to an empty string which will cause a cast error. Is there a sophisticated way to try the cast without erroring on non-numeric values, or should I just do check beforehand? The cast code below is the code which will error when the TemplateId value in the grid is not numeric.

i开发者_运维技巧nt TemplateId = (int)GVSummary.DataKeys[rowIndex].Values["TemplateId"];


int.TryParse():

http://msdn.microsoft.com/en-us/library/f02979c7.aspx

0

精彩评论

暂无评论...
验证码 换一张
取 消