Thread: Checkbox
View Single Post
  #2 (permalink)  
Old January 29th, 2011, 12:52 PM
Imar's Avatar
Imar Imar is offline
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Hi there,

You can clear the Label's Text before you start the loop:

Code:
 
Protected Sub CheckBoxList1_SelectedIndexChanged(ByVal sender As Object, _
ByVal e As EventArgs) Handles CheckBoxList1.SelectedIndexChanged

  lbl1.Text = String.Empty
  For i As Integer = 0 To CheckBoxList1.Items.Count - 1
    If CheckBoxList1.Items(i).Selected Then
      lbl1.Text &= CheckBoxList1.Items(i).Text + "<br/>" 
      ...
End Sub
Alternatively, you can set the Label control's EnableViewState to False in the Mark Up:

Code:
 
<asp:Label ID="lbl1" runat="server" EnableViewState="False" .... />
This way, the Label's Text is automatically reset after each post back.

Hope this helps,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
Reply With Quote
The Following User Says Thank You to Imar For This Useful Post:
123mehran (January 29th, 2011)