Hi all,

I'm newbie of ASP.net , I had create a datagrid which enabled user edit record within the datagrid. Before the user update the record into the database the page will calling a confirm messagebox from msgbox.dll to get confirmation from user. If the user click on OK then the update statement will be proceed and prompt a message to indicate update completed.

But now my issue is the sequence of messagebox is wrong in which it will execute the update statement. Afterward, the confirm alert messagebox.

Anyone know the reason or solution?

I posted my code behind.


ASP Code:
  1. Private Sub dgSchoolName_UpdateCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles dgSchoolName.UpdateCommand
  2.         Dim myds As New DataSet
  3.         Dim myDT As New DataTable
  4.         Dim mydr As DataRow
  5.         Dim strsql As String, strUpdateSqL(0) As String
  6.         Dim dgTxtSchoolName As TextBox = CType(e.Item.Cells(2).FindControl("txtSchoolName"), TextBox)
  7.         Dim dgSchoolNo As String = Convert.ToString(e.Item.Cells(1).Text)
  8.         Dim getSchoolName As String = dgTxtSchoolName.Text
  9.         strsql = "SELECT SchoolName From SchoolName WHERE SchoolNo = '" & dgSchoolNo & "'"
  10.         Try
  11.             MsgBox2.confirm("Do you want to update for School No " + e.Item.Cells(1).Text + " ?", "Confirmation")
  12.             If (IsPostBack) Then
  13.                 If Request.Form("Confirmation") = 1 Then
  14.                     Request.Form("Confirmation").Replace("1", "0")
  15.                 End If
  16.             End If
  17.  
  18.             myds = myC.GetRecordSet(strsql, "Greenwave", "SchoolName", "GreenWave.xml")
  19.             myDT = myds.Tables("SchoolName")
  20.  
  21.             If myDT.Rows.Count = 0 Then
  22.                 MsgBox1.alert("Record Not Found, Update Failed")
  23.                 Me.dgSchoolName.EditItemIndex = -1
  24.                 Exit Sub
  25.             Else
  26.                 If dgTxtSchoolName.Text = vbNullString Then
  27.                     MsgBox1.alert("School Name cannot be blank")
  28.                     Exit Sub
  29.                 Else
  30.                     strUpdateSqL(0) = "UPDATE SchoolName" & _
  31.                                    " SET SchoolName = '" & getSchoolName & "'" & _
  32.                                    " WHERE SchoolNo = '" & dgSchoolNo & "'"
  33.  
  34.                     If (myC.Ins_Update_DeleteRecord(strUpdateSqL, "Greenwave", "GreenWave.xml")) = True Then
  35.                         MsgBox1.alert("Update Completed")
  36.                     Else
  37.                         MsgBox1.alert("Failed to Update")
  38.                     End If
  39.                 End If
  40.             End If
  41.             Me.dgSchoolName.EditItemIndex = -1
  42.             dgSchoolName.DataBind()
  43.         Catch ex As Exception
  44.         End Try
  45.  
  46.     End Sub