Page view counter

How to stop duplicate data being entered into a listbox from selecting multiple checkboxes?

Last post 01-10-2008 9:23 AM by xyz789. 3 replies.

Sort Posts:

  • How to stop duplicate data being entered into a listbox from selecting multiple checkboxes?

    01-09-2008, 5:13 PM
    • Loading...
    • xyz789
    • Joined on 01-29-2007, 12:43 PM
    • Posts 117

    I have a checkbox inside each row of a gridview. When the user sets the checkbox to true, one value for that particular row will be inserted into a Listbox.

    Now the problem is when the user selects multiple checkboxes, the code inside the Checkbox1_Change method will cause duplicate data in the Listbox.

    For an example the listbox may look something like this for the first selection:

    LISTBOX

    23

    The second row may look like this when the user selects a second row. The column course_id gets its value from the checkbox, but it is being duplicated.

    LISTBOX

    First Selection

    23

    Second Selection

    23

    Second Selection

    24

    Is there a way to check for the first value so it won’t be entered in twice?

    I know the problem, but I don't know for sure how to solve it. Here is the code for the Checkbox1_Change method:

     Protected Sub CheckBox1_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs)
           For Each gvr As GridViewRow In GridView1.Rows           
           
    If (CType(gvr.FindControl("CheckBox1"), CheckBox)).Checked = True Then
                scheduleid = CType(gvr.Cells(1).FindControl("Label1"), Label).Text
                lstClassDisplay.Items.Add(CType(gvr.Cells(1).FindControl("Label1"), Label).Text)
            End If        
         
    Next gvr

      End Sub  


    Thanks,xyz789  

     

  • Re: How to stop duplicate data being entered into a listbox from selecting multiple checkboxes?

    01-09-2008, 5:43 PM
    • Loading...
    • lax4u
    • Joined on 05-28-2004, 2:45 PM
    • Posts 714

    clear the list box before adding :):)

  • Re: How to stop duplicate data being entered into a listbox from selecting multiple checkboxes?

    01-09-2008, 5:45 PM
    Answer
    • Loading...
    • lax4u
    • Joined on 05-28-2004, 2:45 PM
    • Posts 714

    so before foreach statement do

    lstClassDisplay.Items.Clear()

  • Re: How to stop duplicate data being entered into a listbox from selecting multiple checkboxes?

    01-10-2008, 9:23 AM
    • Loading...
    • xyz789
    • Joined on 01-29-2007, 12:43 PM
    • Posts 117

    That did work, thank you a lot for the help.

     

    xyz789

Page 1 of 1 (4 items)
Microsoft Communities