0

嗨,我即将通过在动态填充的 Gridview 上创建的文本框更新一些数据,但遗憾的是,当我单击更新按钮时,我的代码无法读取我在这些文本框中输入的内容。这是我的代码:

sqlcon = New SqlConnection(conString)

        Dim id = GridAnswers.DataKeys(e.RowIndex).Value
        Dim row As GridViewRow = TryCast(GridAnswers.Rows(e.RowIndex), GridViewRow)
        Dim ChoiceDescription As TextBox = TryCast(row.FindControl("ChoiceDescription"), TextBox)
        Dim Rating As TextBox = TryCast(row.FindControl("Rating"), TextBox)
        DropDownList)
        Using sqlcon As New SqlConnection
        Dim sql As String = "UPDATE CS_RefQuestionChoice SET ChoiceDescription=@choice, RatingID=@ratingid WHERE ChoiceID=@qid"
        Using cmd As New SqlCommand(sql, sqlcon)
            cmd.Parameters.AddWithValue("@choice", ChoiceDescription.Text)
            cmd.Parameters.AddWithValue("@ratingid", Rating.Text)
            cmd.Parameters.AddWithValue("@id", id)
            sqlcon.Open()
            cmd.ExecuteNonQuery()
            sqlcon.Close()
        End Using
         End Using
        GridAnswers.EditIndex = -1
        gridbind()
4

1 回答 1

0

仅当页面未回发时才检查以绑定网格视图。

于 2013-07-16T09:05:03.953 回答