 |
|
แก้ไขข้อมูลใน Gridview กรณีที่มีช่องสำหรับใส่ภาพลงไปเพื่อแก้ไข ควรทำยังไงดี |
|
 |
|
|
 |
 |
|
ในกรณีที่มีการแก้ไขข้อมูลอ่ะค่ะ แล้วมีช่องสำหรับใส่ภาพลงไปเพื่อแก้ไข เงื่อนไขคือถ้ามีรูปใหม่ให้ไป save แทนรูปเก่าหรือถ้าไม่มีรูปที่จะอัพก็ให้คงรูปเก่าไว้ก่อน
ปล. ตอนนี้เขียนโค้ดได้แค่ใส่รูปใหม่ตอนกดแก้ไขแต่ติดตรงที่พอเราไม่กดเลือกรูปตอนแก้ไข พออัพเดตเสร็จรูปก็กลายเป็นภาพว่างๆ อ่ะค่ะ
Code (VB.NET)
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
Tag : ASP, Web (ASP.NET), VB.NET
|
|
 |
 |
 |
 |
Date :
2015-10-26 15:35:51 |
By :
heaunn |
View :
783 |
Reply :
4 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (VB.NET)
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()
เพิ่มเงื่อนไขประมารนี้ครับ
|
 |
 |
 |
 |
Date :
2015-10-26 17:28:53 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลองเขียนตามโค้ดที่ให้มาแล้วค่ะแต่พอกดอัพเดตรูปที่ควรมีก็หายไปเหมือนเดิมอ่ะค่ะ

|
ประวัติการแก้ไข 2015-10-26 21:48:14
 |
 |
 |
 |
Date :
2015-10-26 21:36:40 |
By :
heaunn |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
หาวิธีแก้ได้แล้วขอบคุณค่ะ 
|
 |
 |
 |
 |
Date :
2015-10-27 03:14:27 |
By :
heaunn |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|

|
 |
 |
 |
 |
Date :
2015-10-27 12:01:28 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|