ในกรณีที่มีการแก้ไขข้อมูลอ่ะค่ะ แล้วมีช่องสำหรับใส่ภาพลงไปเพื่อแก้ไข เงื่อนไขคือถ้ามีรูปใหม่ให้ไป save แทนรูปเก่าหรือถ้าไม่มีรูปที่จะอัพก็ให้คงรูปเก่าไว้ก่อน
Protected Sub gridStore_RowUpdating(sender As Object, e As GridViewUpdateEventArgs)
Dim storeID As TextBox = CType(gridStore.Rows(e.RowIndex).FindControl("txtstoreID"), TextBox)
Dim storeName As TextBox = CType(gridStore.Rows(e.RowIndex).FindControl("txtstoreName"), TextBox)
Dim active As RadioButtonList = CType(gridStore.Rows(e.RowIndex).FindControl("rdbactive"), RadioButtonList)
Dim online As RadioButtonList = CType(gridStore.Rows(e.RowIndex).FindControl("rdbonline"), RadioButtonList)
Dim fiUpload As FileUpload = CType(gridStore.Rows(e.RowIndex).FindControl("fiUpload"), FileUpload)
Dim UlFileName As String = "Image_Store/" & fiUpload.FileName
If fiUpload.HasFile Then
UlFileName += fiUpload.FileName
fiUpload.SaveAs(Server.MapPath(UlFileName))
End If
Dim SqlCon As New SqlConnection(con)
Dim cmd As New SqlCommand("UPDATE Store SET storeName='" & storeName.Text & "', active='" & active.SelectedValue & "', online='" & online.SelectedValue & "', storePic='" & UlFileName & "' WHERE storeID='" & storeID.Text & "'", SqlCon)
SqlCon.Open()
cmd.ExecuteNonQuery()
SqlCon.Close()
gridStore.EditIndex = -1
loadStore()
End Sub
Dim UlFileName As String = "Image_Store/" & fiUpload.FileName
Dim strUpdateFile = String.Empty
If fiUpload.HasFile Then
UlFileName += fiUpload.FileName
fiUpload.SaveAs(Server.MapPath(UlFileName))
strUpdateFile = " , storePic='" & UlFileName & "' "
End If
Dim SqlCon As New SqlConnection(con)
Dim cmd As New SqlCommand("UPDATE Store SET storeName='" & storeName.Text & "', active='" & active.SelectedValue & "', online='" & online.SelectedValue & "' " & strUpdateFile & " WHERE storeID='" & storeID.Text & "'", SqlCon)
SqlCon.Open()
cmd.ExecuteNonQuery()
SqlCon.Close()