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
精彩评论