Protected Sub GridViewExe_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles GridViewExe.RowUpdating
Dim result As String = MsgBox("Do you want to update yes/no ", MsgBoxStyle.YesNoCancel, "Update data")
IdCount = GridViewExe.DataKeys.Item(e.RowIndex).Value.ToString()
Select Case result
Case MsgBoxResult.Yes
Dim txtQuestion As TextBox = CType(GridViewExe.Rows(e.RowIndex).FindControl("txtEditQuestion"), TextBox)
Dim txtSentence As TextBox = CType(GridViewExe.Rows(e.RowIndex).FindControl("txtEditSentence"), TextBox)
Dim txtChoise1 As TextBox = CType(GridViewExe.Rows(e.RowIndex).FindControl("txtEditChoise1"), TextBox)
Dim txtChoise2 As TextBox = CType(GridViewExe.Rows(e.RowIndex).FindControl("txtEditChoise2"), TextBox)
Dim txtChoise3 As TextBox = CType(GridViewExe.Rows(e.RowIndex).FindControl("txtEditChoise3"), TextBox)
Dim txtChoise4 As TextBox = CType(GridViewExe.Rows(e.RowIndex).FindControl("txtEditChoise4"), TextBox)
Dim txtAnswer As TextBox = CType(GridViewExe.Rows(e.RowIndex).FindControl("txtEditAnswer"), TextBox)
conn.Open()
Dim sqlUpdate As String = "update Exercises set Question='" + txtQuestion.Text + _
"' ,Sentence='" + txtSentence.Text + _
"' ,AnsChoise1='" + txtChoise1.Text + _
"' ,AnsChoise2='" + txtChoise2.Text + _
"' ,AnsChoise3='" + txtChoise3.Text + _
"' ,AnsChoise4='" + txtChoise4.Text + _
"' ,Answer='" + txtAnswer.Text + _
"' where Id_Question ='" + IdCount + "'"
Dim sqlComUpdateExe As New SqlCommand(sqlUpdate, conn)
sqlComUpdateExe.ExecuteNonQuery()
conn.Close()
GridViewExe.EditIndex = -1
ddlLevelExe.Enabled = True
ddlTypeExe.Enabled = True
GridViewExe.ShowFooter = True
BindData()
Tag : .NET, Web (ASP.NET), VB.NET, VS 2008 (.NET 3.x), VS 2010 (.NET 4.x)
Protected Sub modEditCommandGridview02(ByVal sender As Object, ByVal e As GridViewEditEventArgs)
GridView02.EditIndex = e.NewEditIndex
viewGridview()
End Sub
Protected Sub modCancelCommandGridview02(ByVal sender As Object, ByVal e As GridViewCancelEditEventArgs)
GridView02.EditIndex = -1
GridView02.ShowFooter = False
viewGridview()
End Sub
Protected Sub myGridView_RowDataBoundGridview02(ByVal source As Object, ByVal e As GridViewRowEventArgs)
'*** Edit ***'
If e.Row.RowType = DataControlRowType.DataRow Then
If (e.Row.RowState And DataControlRowState.Edit) > 0 Then
'*** Detail ***'
Dim lbldetailGridviewEdit As Label = DirectCast(e.Row.FindControl("lbldetail_gridview"), Label)
If Not IsNothing(lbldetailGridviewEdit) Then
lbldetailGridviewEdit.Text = e.Row.DataItem("MJU02UPLOADFILESCANDETAIL")
End If
End If
End If
End Sub
Protected Sub modUpdateCommandGridview02(ByVal sender As Object, ByVal e As GridViewUpdateEventArgs)
Try
'*** Detail ***'
' Dim row As GridViewRow = DirectCast(GridView02.Rows(e.RowIndex), GridViewRow)
' Dim txtdetail As TextBox = DirectCast(row.FindControl("txtdetail"), TextBox)
Dim txtdetail As TextBox = DirectCast(GridView02.Rows(e.RowIndex).FindControl("txtdetail"), TextBox)
'Dim txtdetail As TextBox = CType(GridView02.Rows(e.RowIndex).FindControl("txtdetail"), TextBox)
Dim strSQL = "UPDATE MJU02UPLOADFILESCAN SET MJU02UPLOADFILESCANDETAIL = '" & txtdetail.Text & "' " & _
" WHERE MJU02UPLOADFILESCANID = " & GridView02.DataKeys.Item(e.RowIndex).Value & ""
cmd = New OracleCommand(strSQL, cn)
cmd.ExecuteNonQuery()
Catch ex As NullReferenceException
End Try
GridView02.EditIndex = -1
If Not Page.IsPostBack() Then
viewGridview()
End If