“Input string was not in a correct format.”

后端 未结 5 1951

I am working on a project in which I have a form through which I can edit a question available in a list view. Whenever I select a row from the list view and click on the \'

5条回答
  •  囚心锁ツ
    2020-12-11 02:46

    whenever i try to compile the code it says "{"Input string was not in a correct format."}"

    This error won't come on compiling.

    Now the error comese because you are trying to parse an invalid string to integer. To do it in a safe manner, you should do it like this

    int questionID;
    if(int.TryParse(vTwoOrMoreOptions.SelectedItems[0].Text.ToString(),out questionID))
    {
    //success code
    }
    else
    {
     //failure code
    }
    

提交回复
热议问题