input string was not in a correct format?

Posted by Tejamanimala under C# on 6/6/2013 | Points: 10 | Views : 2471 | Status : [Member] | Replies : 2
hi am getting this error,what is the meaning of this error.how should i detect this error?
am getting the error like this

C# code is....


protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{

if (e.Row.RowType == DataControlRowType.DataRow)
{
Image img = (Image)e.Row.FindControl("resultImage");

Double SelectedOption =Double.Parse(e.Row.Cells[2].Text); //First cell - change accordingly
Double CorrectOption = Double.Parse(e.Row.Cells[3].Text); //Second cell - change accordingly

if (SelectedOption == CorrectOption) img.ImageUrl = "~/D:/pratyusha/project/newonlineexam/newonlineexam/Pictures/correct.jpg";
else if (SelectedOption != CorrectOption) img.ImageUrl = "~/D:/pratyusha/project/newonlineexam/newonlineexam/Pictures/wrong.jpg";

}
}

Server Error in '/' Application.

Input string was not in a correct format.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.FormatException: Input string was not in a correct format.

Source Error:


Line 29: {
Line 30:
Line 31: if (e.Row.RowType == DataControlRowType.DataRow) Line 32: {
Line 33: Image img = (Image)e.Row.FindControl("resultImage");

Source File: D:\pratyusha\project\newonlineexam\newonlineexam\DotNetResultAdmin.aspx.cs Line: 31

Stack Trace:


[FormatException: Input string was not in a correct format.] System.Number.ParseDouble(String value, NumberStyles options, NumberFormatInfo numfmt

manimala


Responses

Posted by: Niladri.Biswas on: 6/6/2013 [Member] Platinum | Points: 25

Up
0
Down
User TryParse instead!

Best Regards,
Niladri Biswas

Tejamanimala, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Tejamanimala on: 6/6/2013 [Member] Starter | Points: 25

Up
0
Down
ya i tried i got it,but image is not diaplying,can you please check my source code,
<ItemTemplate>
<asp:Image ID="resultImage" runat="server" ImageUrl='<%# "~/D:/pratyusha/project/newonlineexam/newonlineexam/Pictures/" + ((Eval("CorrectOption") == Eval("SelectedOption")) ? "correct.jpg" : "wrong.jpg") %>' />

</ItemTemplate>

manimala

Tejamanimala, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response