messagebox for validation onrowupdating in gridview

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • aqua62
    New Member
    • Oct 2008
    • 2

    messagebox for validation onrowupdating in gridview

    Code:
    Protected Sub GridView1_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles GridView1.RowUpdating
    
            ' ''Dim role1 As String
    
            ' ''role1 = e.NewValues(0).ToString
    
            'string myLastName = e.NewValues[1].ToString();
    
    
    
            ' Dim tb As TextBox = GridView1.Rows.Item(e.RowIndex).FindControl("txt_role")
    
            'Dim role_name As String
    
            'role_name = tb.Text
    
    
            Dim str1, str2 As String
            Dim ds1, ds2 As New DataSet
    
            lobId = DropDownList1.SelectedItem.Value
            duId = DropDownList2.SelectedItem.Value
            projectId = DropDownList3.SelectedItem.Value
            roleId = DropDownList4.SelectedItem.Value
    
    
    
    
            Dim sID As String = GridView1.DataKeys(e.RowIndex).Values(0).ToString
    
            Dim txt_role As TextBox = CType(GridView1.Rows.Item(e.RowIndex).FindControl("txt_role"), TextBox)
    
            Dim rolename As String = Convert.ToString(txt_role.Text)
            GridView1.EditIndex = -1
            GridView1.DataBind()
    
            Dim cnt As Integer
            str1 = "SELECT COUNT(*) FROM role  WHERE (role = '" & rolename & "' and role.project_id='" & projectId & "' )"
    
    
            da1 = New SqlDataAdapter(str1, con)
            da1.Fill(ds1)
            cnt = (ds1.Tables(0).Rows(0).Item(0))
    
            If (cnt >= 1) Then
                'flag = True
    
                MsgBox("role exists, enter different")
    
                txt_role.Text = ""
                txt_role.Focus()
    
                Exit Sub
    
            Else
                'GridView1.UpdateRow(0, True)
    
                str2 = "update role set role = '" & rolename & "'   where  role_id = '" & roleId & "' and  project_id = '" & projectId & "' "
    
                da2 = New SqlDataAdapter(str2, con)
                da2.Fill(ds2)
    
            End If
    
    
        End Sub
    I want to check that the same role is not entered, but the problem is that it displays the messagebox on repitition of values but still updates the repeated values in the database
    Last edited by DrBunchman; Oct 6 '08, 03:02 PM. Reason: Added [Code] Tags - Please use the '#' button
Working...