How to transfer integers from textbox into listbox

I am trying to make this so the user will input values into two different textboxs, the values will be multiplied by each other and the result will be placed into a listbox.

I've tried to make this code work a few ways but with no luck:

protected void Button2_Click(object sender, EventArgs e)
    {
        MySqlCommand cmd = new MySqlCommand("SELECT * FROM pets", cs);
        cs.Open();
        MySqlDataReader dr = cmd.ExecuteReader();
        GridView1.DataSource = dr;
        GridView1.DataBind();
        cs.Close();

        int dogWeight;
        dogWeight = Convert.ToInt32(petWeight.Text);
        dogWeight = int.Parse(petWeight.Text);

        int dogFood;
        dogFood = Convert.ToInt32(petFood.Text);
        dogFood = int.Parse(petFood.Text);

        int dogCosts;
        dogCosts = dogFood * dogWeight;

        ListBox1.Items.Add(dogCosts);
    }

Any help would be great

Answers


You need to add ListItem into ListBox instead of integer value - dogCosts

ListBox1.Items.Add(new ListItem(dogCosts.ToString(), dogCosts.ToString()));

If you do not want care about Value, you can just create with Text.

ListBox1.Items.Add(new ListItem(dogCosts.ToString()));

Need Your Help

Minimum number of points in retrieval of affine transform?

image-processing numpy linear-algebra affinetransform

I am trying find a 2-D affine tranform given two points using the solution given by Kloss, and Kloss in “N-Dimensional Linear Vector Field Regression with NumPy.” (2010, The Python Papers Source Co...

Viewing a Documentation Set on OSX

ios objective-c xcode macos

Via the AppleDoc project I have managed to generate a DocSet for my IOS 4.0 project.