Click here to Skip to main content
15,906,231 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
VB
Protected Sub TPdataCCXXXXX_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles TPdataCCXXXXX.RowUpdating
        'Dim tblTrainingPlan = New SqlClient.SqlDataAdapter
        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()
        'TPdataCCXXXXX.EditIndex = -1
        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
Posted
Updated 10-May-11 14:57pm
v2
Comments
[no name] 10-May-11 22:26pm    
Add what is the error? Are we expected to just know telepathically?
janwel 11-May-11 1:59am    
Sir ive got it now thanks anyway

1 solution

remove comment of
TPdataCCXXXXX.EditIndex = -1 you can get your requirement.
 
Share this answer
 
Comments
Pong D. Panda 11-May-11 1:05am    
This is so wrong.
LakshmiNarayana Nalluri 11-May-11 2:26am    
what error did u get?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900