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

selecting a font from the font-family in css

css css3 firefox fontfamily

It's supposed that the font-family holds several font names for those times that the browser doesn't support the first one. it check the second font name and so on.

Scrape using Beautiful Soup preserving   entities

python html web-scraping beautifulsoup html-entities

I would like to scrape a table from the web and keep the   entities intact so that I can republish as HTML later. BeautifulSoup seems to be converting these to spaces though. Example:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.