Click here to Skip to main content
15,892,575 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In my project i have two pages In first i have bind data in grid and in second i want to insert data so i have made a query string for it in first page but when i am passing that query string in second page it shows System.FormatException: Input string was not in a correct format. exception
My code is as
C#
  if (e.CommandName == "AddMasterData")
        {
            Response.Redirect("SubMasterData.aspx?ValueTypeID=" + Convert.ToString(e.CommandArgument) + "?mode=Add");
        }

and on second page 
 TenderManagement.Model.ValueType masterdata = new TenderManagement.Model.ValueType();
        masterdata.ValueTypeID = Convert.ToDecimal(Request.QueryString["ValueTypeID"]);
        masterdata.ValueTypeName = Convert.ToString(txtSubMasterData.Text.Trim());

can anyone help !!
thanks in advance :)
Posted

is e.CommandArgument a Decimal?
I'm not sure, but after Convert.ToString(e.CommandArgument) you do + "?mode=Add" I think it should be + "&mode=Add"

hope this helps.
 
Share this answer
 
Comments
Vishal Pand3y 8-Apr-13 3:02am    
no its not working and e.CommandArgument is a string
Vishal Pand3y 8-Apr-13 3:25am    
actually problem is not on the first part of code its in second part ie
masterdata.ValueTypeID = Convert.ToDecimal(Request.QueryString["ValueTypeID"]);
What to pass is query string ???
V. 8-Apr-13 3:36am    
Make sure the value of e.CommandArgument is parsable as Decimal. if there it contains letters or signs other then + or - it will fail. You can set a breakpoint on that line. Then when it breaks, select Request.QueryString["ValueTypeId"] and right-click. Select quickwatch from the dropdown and check what's in the value.
hi pandey,
first modify the request like below...
Response.Redirect("SubMasterData.aspx?ValueTypeID=" + Convert.ToString(e.CommandArgument) + "&mode=Add");

masterdata.ValueTypeID = Convert.ToDecimal(Request.QueryString["ValueTypeID"]);

The string should contains only numbers,it is possible convert into decimal.
If it contains any letters it cannot parse to decimal. Otherwise U should change the datatype of the valuetypeid to string.
 
Share this answer
 
Comments
Vishal Pand3y 8-Apr-13 3:32am    
thnks for help

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900