2014年7月13日 星期日

[RESOLVED] Template Field does not update


I am unable to get the the update to pull the value after I change in the Text box in the template.


It uses the original value.


I don't get any errors.










  Protected Sub GridView1_RowUpdating(sender As Object, e As GridViewUpdateEventArgs) Handles GridView1.RowUpdating

Dim sappn As String
Dim strSQL As String
Dim intPriority As Integer

sappn = GridView1.Rows(e.RowIndex).Cells(4).Text

Dim txtName As New TextBox
Dim row As GridViewRow = GridView1.Rows(e.RowIndex)
txtName = TryCast(row.FindControl("txtPriority"), TextBox)

strSQL = "UPDATE tbdevassignments SET dbPriority = '" & txtName.Text & "' WHERE SAPPN = '" & sappn & "';"

Response.Write(txtName.Text)

Dim myCommand As New MySqlCommand(strSQL)

myWriteConn.Open()
myCommand.Connection = myWriteConn
myCommand.ExecuteNonQuery()
myCommand.Connection.Close()
myWriteConn.Close()

GridView1.EditIndex = -1
GridView1Refresh()

End Sub







If you're databinding the grid in page_load make sure you do that inside of an if (! IsPostBack) block. 



Move your code in event 'RowUpdated' of your grid. Hope this helps.



Dear 


You Should do this RowDataBound in a grid View if ou are using 




Thanks MetalAsp.Net !!


沒有留言:

張貼留言