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
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