c# - Input string was not in a correct format. (Editable Gridview) -
Whenever I try to edit the information inside my gridview, it throws me this error ... .
Here is my code for edit
protected zero GRDTech_RowEditing (Object Sender, GridViewEditEventArgs e) {GRDTech.EditRowStyle.BackColor = System.Drawing.Color.LightYellow ; GRDtech EditIndex = E. New edits index; BindData (); } And here is my code:
compared to boolResults = true; Text box txtAddFROMKMREAD = (textbox) default._def.readyTech .FooterRow.FindControl ("txtAddFROMKMREAD"); Dropdown list drpPlateNum = (dropdown list) default._def.GEtech .FooterRow.FindControl ("drpPlateNum"); String txt = txtAddFROMKMREAD.Text; Int readDepartureKM = Convert.ToInt32 (txtAddFROMKMREAD.Text); Text box txtAddTOKMREADING = (text box) Default._def .GRDTech.FooterRow.FindControl ("txtAddTOKMREADING"); Int Accessbrating = Convert. ToInt32 (txtAddTOKMREADING.Text); Compared Response = (ArrivalCamreding & lt; readDepartureKM); part int readDepartureKM is giving me an error that the input string is wrong. How do I fix this? "Text" itemprop = "text"> It looks like you have value in txtAddTOKMREADING.Text a vlid
integer is not (can it be empty?). When you are not sure that the text is valid (for example, when you use the textbox for an input from the user), it is better to use it int.TryParse : Represents the representation of a string of numbers in its 32-bit signed integer equivalent of:
. Return value indicates that the conversion is successful.
int readDepartureKM; Bool parsedSuccessfully = int.TryParse (txtAddFROMKMREAD.Text, readDepartureKM out) if (parsedSuccessfully) {// value readDepartureKM do something with that} else {// something else (maybe an error message?) String message = string Format ("'{0}' is not a valid integer.", TxtAddFROMKMREAD.Text); }
Comments
Post a Comment