Hi guys, got a problem here. As you see ive created a datagrid where data comes from the SQL server. my problem is when i hit the update button the data is manipulated but it is still in update format. you have to click cancel first to return to your gridview
here is my code
Protected Sub TPdataCCXXXXX_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles TPdataCCXXXXX.RowUpdating
Dim row As GridViewRow = TPdataCCXXXXX.Rows(e.RowIndex)
Dim txtID As TextBox = row.FindControl("txtID")
Dim txtCourseTitle As TextBox = row.FindControl("txtCourseTitle")
Dim txtCourseCode As TextBox = row.FindControl("txtCourseCode")
Dim txtObjectives As TextBox = row.FindControl("txtObjectives")
Dim txtDuration As TextBox = row.FindControl("txtDuration")
Dim con As New SqlClient.SqlConnection("Data Source=ML0003135586;Initial Catalog=TestSQL;Integrated Security=True")
con.Open()
Dim cmd As New SqlClient.SqlCommand(("update tblTrainingPlan set CourseTitle='" + txtCourseTitle.Text & "' where ID='") + txtID.Text & "'", con)
cmd.ExecuteNonQuery()
con.Close()
BindGrid()
End Sub
Protected Sub TPdataCCXXXXX_RowEditing(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewEditEventArgs) Handles TPdataCCXXXXX.RowEditing
TPdataCCXXXXX.EditIndex = e.NewEditIndex
BindGrid()
End Sub
Protected Sub TPdataCCXXXXX_RowCancelingEdit(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCancelEditEventArgs) Handles TPdataCCXXXXX.RowCancelingEdit
TPdataCCXXXXX.EditIndex = -1
BindGrid()
End Sub
Public Sub Bindgrid()
Dim con As New SqlClient.SqlConnection("Data Source=ML0003135586;Initial Catalog=TestSQL;Integrated Security=True")
con.Open()
Dim DA = New SqlClient.SqlDataAdapter("SELECT [ID], [CourseTitle], [CourseCode], [Objectives], [Duration] FROM [tblTrainingPlan]", con)
Dim myCommand As SqlClient.SqlCommand = New SqlClient.SqlCommand("SELECT [ID], [CourseTitle], [CourseCode], [Objectives], [Duration] FROM [tblTrainingPlan] WHERE ([CostCenter] = @CostCenter)", con)
myCommand.Parameters.AddWithValue("@CostCenter", drpcc.Text)
Dim ds As New DataSet
DA.SelectCommand = myCommand
DA.Fill(ds)
TPdataCCXXXXX.DataSource = ds
TPdataCCXXXXX.DataBind()
con.Close()
End Sub
when i add TPCCXXXXXX.EditIndex = -1 an error shows
Pls help. Thanks for the time and more power