เมื่อตอนเรา กดปุ่ม Edit ต้องการให้มี Dropdownlist(เรียก data มาจาก DB น่ะครับ)ใส่ใน DetailsView น่ะครับ
ต้องทำไงมั้งครับ หรือว่าผมต้องเปลี่ยนไปใช้งาน Controls ตัวอื่น ช่วยแนะนำหน่อย ครับ ทำโปรเจ็คครับผม ยังไม่เสร็จเลย Help Me Please!
ผมลองทำอย่างนี้ดูแล้วเกิดปัญหา น่ะครับ
Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
MultiView1.ActiveViewIndex = RadioButtonList1.SelectedIndex 'เลือกไปยังหน้า View2
src.Bind_Search_person(GridView1)
End Sub
Sub rowEdit(ByVal sender As Object, ByVal e As GridViewEditEventArgs)
strID = GridView1.DataKeys(e.NewEditIndex).Value.ToString
detailsviewBind()
End Sub
Protected Sub GridView1_SelectedIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewSelectEventArgs) Handles GridView1.SelectedIndexChanging
strID = GridView1.DataKeys(e.NewSelectedIndex).Value.ToString
detailsviewBind()
End Sub
Private Sub detailsviewBind()
' BindData to detailsview
mysql = "SELECT * FROM person_table WHERE id_person='" & strID & "'"
conn.Connect()
Dim cmd As New Mysql.Data.MySqlClient.MySqlCommand(mysql, conn.myConnection)
conn.MyReader = cmd.ExecuteReader
DetailsView1.DataSource = conn.MyReader
DetailsView1.DataBind()
conn.MyReader.Close()
End Sub
Protected Sub RadioButtonList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles RadioButtonList1.SelectedIndexChanged
' Check Author ว่าสามารถ เข้าไปสร้าง Account หรือไม่
Dim roles = CType(Session("roles"), String)
If roles = "Administrator" Then
MultiView1.ActiveViewIndex = RadioButtonList1.SelectedValue
Else
MsgBox("ไม่สามารถใช้งานในส่วนนี้ได้ เฉพาะผู้ดูแลระบบ(Administrator)", MsgBoxStyle.OkOnly, "แจ้งเตือน")
Response.Redirect("personel.aspx")
End If
End Sub
Protected Sub DetailsView1_ModeChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DetailsViewModeEventArgs) Handles DetailsView1.ModeChanging
' definite Mode Change of detailsview
Select Case e.NewMode
Case DetailsViewMode.Edit
Dim lblID As Label = CType(DetailsView1.FindControl("lblID"), Label)
strID = lblID.Text
DetailsView1.ChangeMode(DetailsViewMode.Edit)
detailsviewBind()
Case DetailsViewMode.ReadOnly
DetailsView1.ChangeMode(DetailsViewMode.ReadOnly)
End Select
detailsviewBind()
End Sub
Protected Sub DetailsView1_ItemUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DetailsViewUpdateEventArgs) Handles DetailsView1.ItemUpdating
Dim lblID As Label = CType(DetailsView1.FindControl("lblID"), Label)
strID = lblID.Text
Dim txtEditName As TextBox = CType(DetailsView1.FindControl("txtEditName"), TextBox)
Dim txtBirthDate As TextBox = CType(DetailsView1.FindControl("txtBirthDate"), TextBox)
Dim txtAddress As TextBox = CType(DetailsView1.FindControl("txtAddress"), TextBox)
Dim txtTel As TextBox = CType(DetailsView1.FindControl("txtTel"), TextBox)
Dim txtEmail As TextBox = CType(DetailsView1.FindControl("txtEmail"), TextBox)
Dim txtPosition As TextBox = CType(DetailsView1.FindControl("txtPosition"), TextBox)
Dim txtLocation As TextBox = CType(DetailsView1.FindControl("txtLocation"), TextBox)
conn.Connect()
mysql = "UPDATE person_table SET name='" & txtEditName.Text & "',birthdate='" & txtBirthDate.Text & "',address='" & txtAddress.Text & "',"
mysql &= "phonenumber='" & txtTel.Text & "',email='" & txtEmail.Text & "',position='" & txtPosition.Text & "',location='" & txtLocation.Text & "' WHERE id_person='" & strID & "'"
Dim cmd As New Mysql.Data.MySqlClient.MySqlCommand(mysql, conn.myConnection)
cmd.CommandType = Data.CommandType.Text
cmd.CommandText = mysql
cmd.ExecuteNonQuery()
MsgBox(" แก้ไขข้อมูล เรียบร้อย ", MsgBoxStyle.Information, " Confirm !!")
detailsviewBind()
DetailsView1.ChangeMode(DetailsViewMode.ReadOnly)
End Sub