Proper strinfg format

B

bbawa1

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" }

}
 
J

Jimmy V

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
 
P

Patrice

The "input string" is the string you try to convert. Basically it means that
the value that is contained in e.Row.Cells[2].Text can't be converted to
Int32.
 
B

bbawa1

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.
 
D

David R. Longnecker

(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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top