Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Search | Today's Posts | Mark Forums Read
ASP.NET 4 General Discussion For ASP.NET 4 discussions not relating to a specific Wrox book
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 4 General Discussion section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old January 29th, 2011, 12:19 PM
Registered User
 
Join Date: Jan 2011
Posts: 9
Thanks: 6
Thanked 0 Times in 0 Posts
Default Checkbox

Hi
when i checked the item1 and then item2 ,the item1 repeat
like this:http://i53.tinypic.com/20ushz7.png
what should i do?
Code:
   
      Protected Sub CheckBoxList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles CheckBoxList1.SelectedIndexChanged
      For i As Integer = 0 To CheckBoxList1.Items.Count - 1
      If CheckBoxList1.Items(i).Selected Then
      lbl1.Text &= CheckBoxList1.Items(i).Text + "<br/>" 
      End If
      Next
      End Sub
Reply With Quote
  #2 (permalink)  
Old January 29th, 2011, 12:52 PM
Imar's Avatar
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)
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
checkbox grstad HTML Code Clinic 1 December 18th, 2006 08:10 AM
checkbox checked by default by html:checkbox sachin.tathod Struts 3 December 4th, 2006 03:41 PM
checkbox fcm Access VBA 12 April 15th, 2005 08:15 AM
Checkbox johnjohn Classic ASP Basics 2 December 6th, 2004 06:03 PM
checkbox damnnono_86 Access 2 October 10th, 2003 03:25 AM



All times are GMT -4. The time now is 11:45 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.