
June 20th, 2012, 02:39 AM
|
|
Contributing User
|
|
Join Date: Dec 2004
Posts: 81
Time spent in forums: 1 Day 2 h 6 m 19 sec
Reputation Power: 9
|
|
|
Counting the number of items
guys need help i am new to asp.net programming and i cant figure out what could possibly the solution.
ihave two listboxes. the first one contains the items to be selected and added to the other listbox. When i click the add button, the program should count the items that was added on the second list box. I want to put the count in a textbox
here is the code: c#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class _Default : System.Web.UI.Page
{
int count = 0;
int x;
protected void Page_Load(object sender, EventArgs e)
{
if (!(IsPostBack)){
lst1.Items.Add("Red");
lst1.Items.Add("Blue");
lst1.Items.Add("Yellow");
lst1.Items.Add("Black");
}
}
protected void add(object sender, EventArgs e)
{
lst2.Items.Add(lst1.SelectedItem.Text);
count = count + 1;
}
protected void btnRemove_Click(object sender, EventArgs e)
{
lst2.Items.Remove(lst2.SelectedItem);
}
|