Problems with list<T> in Asp.Net c#
Posted
by
Johnathan Nardia
on Stack Overflow
See other posts from Stack Overflow
or by Johnathan Nardia
Published on 2012-12-13T10:30:43Z
Indexed on
2012/12/13
11:04 UTC
Read the original article
Hit count: 273
I'm making a web app in Asp.Net using c# that lets you add items into the list.
My problem is that each time that i click the button to add a new item into the list , its just shows me the last item and the list counter shows me only 1 .
What am I doing wrong??
Here is the code :
public partial class home : System.Web.UI.Page
{
List<string> messageboxs = new List<string>();
public string val = "";
public string data = "";
protected void Button1_Click(object sender, EventArgs e)
{
val = "";
messageboxs.Add(text1.Text);
ListBox1.DataSource = messageboxs;
ListBox1.DataBind();
val = messageboxs.Count.ToString();
}
}
© Stack Overflow or respective owner