How to show Label1.Text for each item in a foreach statement?
Posted
by Mike108
on Stack Overflow
See other posts from Stack Overflow
or by Mike108
Published on 2010-05-09T07:03:52Z
Indexed on
2010/05/09
7:08 UTC
Read the original article
Hit count: 302
I want to show each item Id that is doing now dynamically in a foreach statement.
But the following code only shows the last item Id in Label1.Text.
How to show Label1.Text for each item in a foreach statement?
I use asp.net C#.
protected void Button1_Click(object sender, EventArgs e)
{
List<int> list = new List<int>()
{
1,2,3,4,5
};
foreach (var item in list)
{
Label1.Text = string.Format("I'm doing item {0} now.", item.ToString());
Thread.Sleep(1 * 1000);
}
}
© Stack Overflow or respective owner