<%@ Import Namespace="System.Data"%>
<%@ Import Namespace="System.Data.SqlClient"%>
<%@Import Namespace="System.IO" %>
<%@Import Namespace="System.Timers" %>
<%@ Page Language="VB" %>
<%@ Register Assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
Namespace="System.Web.UI" TagPrefix="asp" %>
<script runat="server">
Dim objConn As SqlConnection
Dim objCmd As SqlCommand
Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
Dim strConnString As String
strConnString = "Server=localhost;UID=sa;PASSWORD=xxxx;database=blooddb;Max Pool Size=400;Connect Timeout=600;"
objConn = New SqlConnection(strConnString)
objConn.Open()
litFullLoad.Text = System.DateTime.Now.ToString()
BindData()
End Sub
Sub IntervalTimer_Tick(ByVal sender As Object, ByVal e As EventArgs)
litrptRefresh.Text = "Repeater data will refreshed at: " + DateTime.Now.ToLongTimeString()
End Sub
Sub BindData()
Dim strSQL As String
strSQL = "SELECT M.HospitalName,C.BloodGroup,C.Quantity,C.Urgency FROM checkmember M INNER JOIN CallEmerge C ON M.Username = C.Username ORDER BY Urgency ASC"
Dim dtReader As SqlDataReader
objCmd = New SqlCommand(strSQL, objConn)
dtReader = objCmd.ExecuteReader()
'*** BindData to Repeater ***'
myRepeater.DataSource = dtReader
myRepeater.DataBind()
dtReader.Close()
dtReader = Nothing
End Sub
Sub myRepeater_ItemCommand(ByVal source As Object, ByVal e As RepeaterCommandEventArgs) Handles myRepeater.ItemCommand
If e.CommandName = "Click" Then
Dim lblHospital As Label = CType(e.Item.FindControl("lblHospital"), Label)
Session("HospitalName") = lblHospital.Text
Response.Redirect("http://localhost/Bloodwidgets/hospitalInfomation.aspx")
End If
End Sub
Sub myRepeater_ItemDataBound(ByVal sender As Object, ByVal e As RepeaterItemEventArgs) Handles myRepeater.ItemDataBound
Dim lblHospital As Label = CType(e.Item.FindControl("lblHospital"), Label)
If Not IsNothing(lblHospital) Then
lblHospital.Text = e.Item.DataItem("HospitalName")
End If
Dim lblBloodGroup As Label = CType(e.Item.FindControl("lblBloodGroup"), Label)
If Not IsNothing(lblBloodGroup) Then
lblBloodGroup.Text = e.Item.DataItem("BloodGroup")
End If
Dim lblQuantity As Label = CType(e.Item.FindControl("lblQuantity"), Label)
If Not IsNothing(lblQuantity) Then
lblQuantity.Text = e.Item.DataItem("Quantity")
End If
'*** Hyperlink ***'
Dim lnkContact As LinkButton = CType(e.Item.FindControl("lnkContact"), LinkButton)
If Not IsNothing(lnkContact) Then
lnkContact.Attributes.Add("OnClick", "return confirm('Delete Record?');")
End If
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
Time When Full Page Load:
<asp:Literal ID="litFullLoad" runat="server"></asp:Literal><br />
<br />
<asp:ScriptManager ID="scManager" runat="server" ></asp:ScriptManager>
<div>
<asp:Timer ID="IntervalTimer" OnTick="IntervalTimer_Tick" runat="server" Interval="15000">
</asp:Timer>
</div>
<asp:UpdatePanel ID="upPanel" UpdateMode="Conditional" runat="server">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="IntervalTimer" EventName="Tick" />
</Triggers>
<ContentTemplate>
Time when Only Repeater data will Referesh : <asp:Literal ID="litrptRefresh" runat="server" Text="<b>repeater not refreshed yet.</b>" ></asp:Literal><br />(Repeater Will Referesh after Every 15 Second)
<br />
<table border="1px">
<tbody>
<asp:Repeater id="myRepeater" runat="server">
<HeaderTemplate>
<table border="1">
<tr>
<th>ชื่อโรงพยาบาล</th>
<th>กรุ๊ปโลหิต</th>
<th>ปริมาณโลหิต(ยูนิต/คน)</th>
<th>ติดต่อ</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td align="left"><asp:Label id="lblHospital" runat="server"></asp:Label></td>
<td align="center"><asp:Label id="lblBloodGroup" runat="server"></asp:Label></td>
<td align="center"><asp:Label id="lblQuantity" runat="server"></asp:Label></td>
<td align="right"><asp:LinkButton id="lnkDelete" CommandName="Click" runat="server">Click!</asp:LinkButton></td>
</ItemTemplate>
</asp:Repeater>
</tbody>
</table>
</ContentTemplate>
</asp:UpdatePanel>
</form>
</body>
</html>
Sub IntervalTimer_Tick(ByVal sender As Object, ByVal e As EventArgs)
litrptRefresh.Text = "Repeater data will refreshed at: " + DateTime.Now.ToLongTimeString()
End Sub
Sub IntervalTimer_Tick(ByVal sender As Object, ByVal e As EventArgs) Handles IntervalTimer.Tick
litrptRefresh.Text = "Repeater data will refreshed at: " + DateTime.Now.ToLongTimeString()
'bind data ให้ repeater อีกทีตรงนี้ด้วย
End Sub