Imports System.Data.OleDb
Public Class user_delete
Inherits System.Web.UI.Page
Dim objConn As OleDbConnection
Dim objCmd As OleDbCommand
Dim strSQL, strConnString As String
Dim dtReader As OleDbDataReader
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Me.Label1.Text = "b5051089"
strConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("App_Data/KU.mdb") & ";Jet OLEDB:Database Password=;"
objConn = New OleDbConnection(strConnString)
objConn.Open()
If Not Page.IsPostBack() Then
BindData()
End If
End Sub
Sub BindData()
strSQL = "SELECT * FROM Reserv_room WHERE User_ID = '" & Me.Label1.Text & "' "
objCmd = New OleDbCommand(strSQL, objConn)
dtReader = objCmd.ExecuteReader()
'*** BindData to Repeater ***'
myRepeater.DataSource = dtReader
myRepeater.DataBind()
dtReader.Close()
dtReader = Nothing
End Sub
Sub Page_UnLoad()
objConn.Close()
objConn = Nothing
End Sub
Private Sub myRepeater__ItemDataBound(ByVal sender As Object, ByVal e As RepeaterItemEventArgs) Handles myRepeater.ItemDataBound
'hplroom แสดงข้อมูลออกมาครับ
Dim hplroom As HyperLink = CType(e.Item.FindControl("hpl1"), HyperLink)
If Not IsNothing(hplroom) Then
hplroom.Text = e.Item.DataItem("RoomID")
hplroom.NavigateUrl = "http:\\www.google.co.th" 'จำลองลิงค์ไว้ก่อนครับ
End If
'hpluser ไม่แสดงข้อมูลครับ
Dim hpluser As HyperLink = CType(e.Item.FindControl("hpl2"), HyperLink)
If Not IsNothing(hpluser) Then
hpluser.Text = e.Item.DataItem("User_ID")
hpluser.NavigateUrl = "http:\\www.google.co.th"
End If
'hplsubject ไม่แสดงข้อมูลเหมือนกันครับ
Dim hplsubject As HyperLink = CType(e.Item.FindControl("hpl3"), HyperLink)
If Not IsNothing(hplsubject) Then
hplsubject.Text = e.Item.DataItem("SubjectID")
hplsubject.NavigateUrl = "http:\\www.google.co.th"
End If
Dim Label4 As Label = CType(e.Item.FindControl("Label4"), Label)
If Not IsNothing(Label4) Then
Label4.Text = e.Item.DataItem("Date_reserv")
End If
Dim Label5 As Label = CType(e.Item.FindControl("Label5"), Label)
If Not IsNothing(Label5) Then
Label5.Text = e.Item.DataItem("Timestart")
End If
Dim Label6 As Label = CType(e.Item.FindControl("Label6"), Label)
If Not IsNothing(Label6) Then
Label6.Text = e.Item.DataItem("Timefinish")
End If
Dim Label7 As Label = CType(e.Item.FindControl("Label7"), Label)
If Not IsNothing(Label7) Then
Label7.Text = e.Item.DataItem("Group_ID")
End If
Dim Label8 As Label = CType(e.Item.FindControl("Label8"), Label)
If Not IsNothing(Label8) Then
Label8.Text = e.Item.DataItem("Status_room")
End If
End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
Dim chkDel As CheckBox
Dim lblID As HyperLink
Dim i As Integer
For i = 0 To myRepeater.Items.Count - 1
chkDel = myRepeater.Items(i).FindControl("chk1")
lblID = myRepeater.Items(i).FindControl("hpl1")
If chkDel.Checked = True Then
strSQL = "DELETE FROM Reserv_room WHERE RoomID = '" & lblID.Text & "' "
objCmd = New OleDbCommand(strSQL, objConn)
objCmd.ExecuteNonQuery()
End If
Next
BindData()
End Sub
End Class
Dim hplroom As HyperLink = CType(e.Item.FindControl("hpl1"), HyperLink)
If Not IsNothing(hplroom) Then
hplroom.Text = e.Item.DataItem("RoomID")
hplroom.NavigateUrl = "http://www.google.co.th" 'จำลองลิงค์ไว้ก่อนครับ
End If
ลอง Debug ดูครับ มันมีค่าหรือเข้าทำงาน IF นี้หรือเปล่า หรือว่า FindControl ไม่เจอ