有关使用Gridview更新数据库的问题 [英] Problem regarding updating database using Gridview

查看:69
本文介绍了有关使用Gridview更新数据库的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

先生,我遇到了另一个问题.当我单击更新"按钮时,弹出一条错误消息,说回发(我不知道这是什么),先生,这是我的代码
来源

Sir ive got another problem. When i Click update button an error pops out saying about post back(i dont know what it is) sir here is my code
on Source

<pre lang="xml"><asp:GridView ID="TPdataCCXXXXX" runat="server" Height="439px" Width="854px" AutoGenerateColumns="False"
       onrowcancelingedit="TPdataCCXXXXX_RowCancelingEdit"
       onrowediting="TPdataCCXXXXX_RowEditing" onrowupdating="TPdataCCXXXXX_RowUpdating">
           <Columns>
              <asp:CommandField ButtonType="Button" ShowEditButton="true" ShowCancelButton="true" />

      <asp:TemplateField HeaderText="CourseTitle">
         <ItemTemplate>
           <%#Eval("CourseTitle")%>
         </ItemTemplate>
         <EditItemTemplate>
           <asp:TextBox runat="server" ID="txtCourseTitle" Text=''<%# Eval("CourseTitle")%>'' />
         </EditItemTemplate>
     </asp:TemplateField>

     <asp:TemplateField HeaderText="CourseCode">
         <ItemTemplate>
           <%#Eval("CourseCode")%>
         </ItemTemplate>
         <EditItemTemplate>
           <asp:TextBox runat="server" ID="txtCourseCode" Text=''<%# Eval("CourseCode")%>'' />
         </EditItemTemplate>
     </asp:TemplateField>

     <asp:TemplateField HeaderText="Objectives">
         <ItemTemplate>
           <%#Eval("Objectives")%>
         </ItemTemplate>
         <EditItemTemplate>
           <asp:TextBox runat="server" ID="txtObjectives" Text=''<%# Eval("Objectives")%>'' />
         </EditItemTemplate>
     </asp:TemplateField>

     <asp:TemplateField HeaderText="Duration">
         <ItemTemplate>
           <%#Eval("Duration")%>
         </ItemTemplate>
         <EditItemTemplate>
           <asp:TextBox runat="server" ID="txtDuration" Text=''<%# Eval("Duration")%>'' />
         </EditItemTemplate>
     </asp:TemplateField>


           </Columns>
       </asp:GridView>


这是我有关更新数据库的代码


Here is my code on Updating database

<pre lang="vb">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 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")
    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()
        If drpcc.Text = "CCXXXXX" Then
            Dim strSQL As String
            Dim connection As SqlClient.SqlConnection = New SqlClient.SqlConnection("Data Source=ML0003135586;Initial Catalog=TestSQL;Integrated Security=True")
            strSQL = "SELECT [ID], [CourseTitle], [CourseCode], [Objectives], [Duration] FROM [tblTrainingPlan] WHERE ([CostCenter] = @CostCenter)"
            connection.Open()
            Dim myCommand As SqlClient.SqlCommand = New SqlClient.SqlCommand(strSQL, connection)
            myCommand.Parameters.AddWithValue("@CostCenter", drpcc.Text)
            TPdataCCXXXXX.DataSource = myCommand.ExecuteReader()
            TPdataCCXXXXX.DataBind()
        ElseIf drpcc.Text = "123" Then
            Dim strSQL As String
            Dim connection As SqlClient.SqlConnection = New SqlClient.SqlConnection("Data Source=ML0003135586;Initial Catalog=TestSQL;Integrated Security=True")
            strSQL = "SELECT [ID], [CourseTitle], [CourseCode], [Objectives], [Duration] FROM [tblTrainingPlan] WHERE ([CostCenter] = @CostCenter)"
            connection.Open()
            Dim myCommand As SqlClient.SqlCommand = New SqlClient.SqlCommand(strSQL, connection)
            myCommand.Parameters.AddWithValue("@CostCenter", drpcc.Text)
            TPdataCCXXXXX.DataSource = myCommand.ExecuteReader()
            TPdataCCXXXXX.DataBind()
        End If
    End Sub



香港专业教育学院得到这样的错误



ive got an error saying like this

<pre lang="xml">Invalid postback or callback argument.  Event validation is enabled using <pages enableEventValidation="true"/> in configuration or <%@ Page EnableEventValidation="true" %> in a page.  For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them.  If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.</pre><br />


请帮我,先生,我不知道到底是什么问题
我的更新代码有误吗?
谢谢,谢谢!


Plss help me sir i dont know what really is the problem
Is my code on updating wrong?
Thanks and more power!

推荐答案

尝试以这种方式

在HTML中添加此行,您将在行顶部看到它.
]]>
try to make this way

in your HTML add this line you will see this at the top of the line.
]]>


这篇关于有关使用Gridview更新数据库的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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