Pregunta

i have a foreach statement populating textboxes with various details about a person from a list.

    public void displaySenior()
    {
        foreach (Senior sp in seniorPlayer.Senior)
        {
            if (comboListSeniorPlayers.SelectedItem == sp.Name)
            {
                txtSeniorName.Text = sp.Name;
                txtAdress.Text = sp.Address;
                txtDOB.Text = sp.DoB;
                txtEmail.Text = sp.Email;
                txtDoctor.Text = sp.DoctorNme;
                txtKnowIssues.Text = sp.Health;
                txtNextofKin.Text = sp.NextOfKin;
                txtPostcode.Text = sp.Pstcode;
                int.Parse(txtPhoneNum.Text) = sp.PhoneNum;

            }
        }
    }

when i try to parse the textbox like this i get an error of "The left-hand side of an assignment must be a variable, property or indexer ".

what would be a way of getting round this ?

thanks for any help and responses !

¿Fue útil?

Solución

Since you mention that sp.PhoneNum is "an int value holding a phone number"

This should be

txtPhoneNum.Text = sp.PhoneNum.ToString(CultureInfo.InvariantCulture);

Otros consejos

This is statement is causing the error. As error saying you have to use a variable on this left hand operand. int.Parse(txtPhoneNum.Text) = sp.PhoneNum;

If you really want to covert then u

txtPhoneNum.Text = int.Parse(sp.PhoneNum)
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top