I have noticed for some time now that when I go to select a control while in a sqlDataSource Wizard as a variable that it shows more than one control with the same name. I am also having a problems with for next loops doubling the data inserted into database tables. What might cause this? I am running Windows Server 2003 and VS2005 with SQL 2005 on the same machine. I remotely write my code from a Windows XP machine.
Here is the for next loop:
Protected Sub Button3_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim StudentUserName As String
For i As Integer = 0 To GridView1.Rows.Count - 1
Dim cb As CheckBox = CType(GridView1.Rows(i).FindControl("StudentCb"), CheckBox)
'If it's checked, delete it...
If cb.Checked Then
'Programmatically access the CheckBox from the TemplateField
Dim StepsTb As TextBox = CType(GridView1.Rows(i).FindControl("StepsTb"), TextBox)
Dim Grade As Integer = 0
If Not StepsTb.Text = "0" Then
Grade = StepsTb.Text
End If
Profile.Score = Grade
'If it's checked, delete it...
StudentUserName = GridView1.DataKeys(i).Value
Profile.StudentUserName = StudentUserName
If Page.IsValid Then
Try
InsertDs.Insert()
'ErrorLb.Text += Grade & " " & StudentUserName & " " & DateTextBox.Text & " " & ClassTb.SelectedValue & "</br>"
Catch ex As Exception
ErrorLb.Text += "The following error occured while trying to update the data: " & ex.ToString() & "<br/>"
ErrorLb.ForeColor = Drawing.Color.Red
End Try
End If
End If
Next
'ErrorLb.Text = "Your information was entered correctly. <br/> "
ErrorLb.ForeColor = Drawing.Color.Green
ErrorLb.Font.Bold = True
GridView2.DataBind()
FormView1.DataBind()
FormView2.DataBind()
End Sub
The code is designed to loop through a templated field's text box on a gridview and enter this information into sql if a check box is checked.