2010-05-09 3 views
0

Je souhaite afficher chaque ID d'élément en cours de manière dynamique dans une instruction foreach. Comment faire un rappel de client pour afficher l'ID de l'élément dans une instruction foreach?Comment effectuer un rappel client pour chaque élément d'une instruction foreach à l'aide de C#?

<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label> 
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" /> 

.

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()); 
Page.RegisterStartupScript("", string.Format("<script>alert('doing item {0} now')</script>", item.ToString())); 
      Thread.Sleep(1 * 1000); 
     } 
    } 

Répondre

Questions connexes