我可以更新我的数据网格,但是您必须单击“取消"按钮以返回 [英] I can update my datagrid but you have to click Cancel button to return

查看:66
本文介绍了我可以更新我的数据网格,但是您必须单击“取消"按钮以返回的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,这里遇到了问题.如您所见,IVE创建了一个数据网格,其中数据来自SQL Server.我的问题是,当我按下更新"按钮时,数据已被处理,但仍处于更新格式.您必须先单击取消"以返回到gridview
这是我的代码

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 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


当我添加TPCCXXXXXX.EditIndex = -1时,显示错误
请帮助.感谢您的时间和更多的力量


when i add TPCCXXXXXX.EditIndex = -1 an error shows
Pls help. Thanks for the time and more power

推荐答案

删除
的评论 TPdataCCXXXXX.EditIndex = -1,可以满足您的要求.
remove comment of
TPdataCCXXXXX.EditIndex = -1 you can get your requirement.


这篇关于我可以更新我的数据网格,但是您必须单击“取消"按钮以返回的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆