开发者

Preventing cast errors

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜