tags:

views:

45

answers:

1

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.

int TemplateId = (int)GVSummary.DataKeys[rowIndex].Values["TemplateId"];
+3  A: 

int.TryParse():

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

Stu