(e-mail address removed)-
I'd try using TryParse first and then incorporate the if/then statement into
it.
// Example of e.Row.Cells[2].Text = "" (a blank string)
string cell2 = "";
// Example of e.Row.Cells[0].Text having it's value set.
string cell0 = "";
int result;
bool success = Int32.TryParse(cell2, out result);
if (success)
cell0 = (result >= 13) ? "Hello" : "";
This checks to see if it CAN parse before it checks your logic of result
= 13. You could also place an else clause in there for when success ==
false. Replace cell2 and cell0 with your e.Row.Cells[0] and [2]; I just needed
a few strings to use to illustrate the point.
For more information on the Int32.TryParse method, check out :
http://msdn2.microsoft.com/en-us/library/f02979c7.aspx
HTH.
-dl
--
David R. Longnecker
http://blog.tiredstudent.com
Have you examined the value of e.Rows.Cells[2].Text to make sure it
holds a value that should convert to int? You can expect this error
when attempting to
Convert.ToInt32("");
--
Jimmy V
.NET Development Team - CTS, Inc
(e-mail address removed)
www.askcts.com
It is giving me error that input string is not in proper format.
What's wrong.
protected void GridView1_RowDataBound(object sender,
GridViewRowEventArgs e)
{
if (Convert.ToInt32(e.Row.Cells[2].Text) >=13)
{
e.Row.Cells[0].Text = "Hello" }
}- Hide quoted text -
- Show quoted text -
It's not holding the value. Please help me I don't know how to fix
it.