I am using a foreach
loop to retrieve data from database and it includes both fields with text and numbers. I need to convert the fields with numbers from string to int to be able to sort the number fields properly.
I tried the following from another thread but it is not working for me:
// Displays the value as string
Convert.ToInt32(item.property);
// Throws an exception error "The best overloaded method match for 'int.TryParse(string out int' has some invalid arguments)"
Int32.TryParse(item.property, out PropertyInt);
Followed following:
How can I convert String to Int?
But this is not working for me in a foreach loop.
Here is my code:
@foreach (var item in db.Query(collection))
{
<tr>
<td>item.name</td>
<td>@Convert.ToInt32(item.value);</td>
<td>Int32.TryParse(item.value, out ItemValueInt);</td>
</tr>
}