Wrox Programmer Forums
| 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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
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
 
Old January 29th, 2011, 12:52 PM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 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!
The Following User Says Thank You to Imar For This Useful Post:
123mehran (January 29th, 2011)




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





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