更新时间:2023-01-22 18:15:56
确实是一个非常困难的错误.
句柄 grdPANSSAssessmentmentSelect.SelectedIndexChanged
或在aspx源文件中找到
onrowdatabound = "
并将其删除.
如果两者都存在,则该事件将被调用两次.
删除任何一个.
它应该可以正常工作
谢谢.希望它不会花费太多时间...:-)
Can someone please tell me why the code below inserts duplicate rows in the one instance and not the other. I checked the grid properties and they are also exactly the same:
Protected Sub GridView1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles grdPANSSAssessmentSelect.SelectedIndexChanged
Dim AssessCode As String = CType(Session.Item("AssessCode"), String)
Session("AssessCode") = grdPANSSAssessmentSelect.SelectedRow.Cells.Item(2).Text
Dim GetAssDate As String
GetAssDate = Format(Date.Today, "dd/MM/yyyy")
'GetAssDate = Strings.Format(Date.Today, "dd/MM/yyyy")
Dim sql As String = "AddAssessment " & Session("ClientID") & "," & Session("AssessCode") & _
",4,'" & GetAssDate & "', '" & GetAssDate & "','" & GetAssDate & "',0,0,0,0,0"
Dim myConnection As New SqlConnection(ConfigurationManager.ConnectionStrings("CameoAssessmentRegisterConnectionString").ConnectionString)
Dim myCommand As New SqlCommand(sql, myConnection)
Dim myReader As SqlDataReader
myConnection.Open()
'Dim reader As SqlDataReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection)
'myCommand.ExecuteNonQuery()
myReader = myCommand.ExecuteReader
If myReader.RecordsAffected > 0 Then
Response.Redirect("frmPANSS.aspx")
Else
ClientScript.RegisterStartupScript(Me.GetType, "test", "<script language='javascript'>alert('There seems to be a problem inserting the assessment. Contact Administrator!);</script>")
End If
myReader.Close()
myConnection.Close()
End Sub
Hi
really a very difficult bug.
took me more than 30 mins.
just remove theHandles grdPANSSAssessmentSelect.SelectedIndexChanged
or in the aspx source file findonrowdatabound="GridView1_RowDataBound"and remove it.
if both are present, then the event will be called twice.
remove any one.
It should work
Thank you. Hope it didn''t take too much out of your day...:-)