 |
|
ถามเรื่องการใช้ AJAX กับ Repeater control ค่ะ ต้องการรีเฟรช repeater control ทุก 15 วินาที ค่ะ |
|
 |
|
|
 |
 |
|
ต้องการรีเฟรช repeater control ทุก 15วินาที ค่ะ พอดีไปเจอเว็บมาเว็บนึงเลยปรับกับของตัวเองดู
ทดลองทำแล้วแต่มันไม่รีเฟรช ให้อ่ะค่ะ พี่ๆ พอมีทางแนะนำมั้ยคะ มีโค๊ดมากางให้ดู หนูเปนมือใหม่อ่ะค่ะ
Code (VB.NET)
<%@ 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>
Tag : - - - -
|
|
 |
 |
 |
 |
Date :
2010-02-23 00:21:50 |
By :
ladyjupz |
View :
1403 |
Reply :
5 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เวลามัน tick มันเปลี่ยนแค่ label ใช่ไหมล่ะ
Code (VB.NET)
Sub IntervalTimer_Tick(ByVal sender As Object, ByVal e As EventArgs)
litrptRefresh.Text = "Repeater data will refreshed at: " + DateTime.Now.ToLongTimeString()
End Sub
ก็สั่งมันแค่นั้น
ต้องสั่งให้มัน bind data ของ repeater ใหม่ด้วย
|
 |
 |
 |
 |
Date :
2010-02-23 07:50:44 |
By :
tungman |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
มันก็ไม่เปลี่ยน label ด้วยค่ะ หรือว่ามันไม่เข้าโพรซีเยอร์ที่รับevent หรือตรง control ที่จับเวลามันมีอะไรผิด
หนูไม่ทราบว่า มันมีปัญหาที่อะไรค่ะ รบกวนพี่ๆช่วยดูให้หน่อยนะคะ
|
 |
 |
 |
 |
Date :
2010-02-23 15:27:08 |
By :
ladyjupz |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
กำหนด event handle ให้มันดูดิ
Code (VB.NET)
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
|
 |
 |
 |
 |
Date :
2010-02-23 15:50:51 |
By :
tungman |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณมากค่ะ อิอิ
หนูได้ทดลองทำตามที่บอกแล้วแต่มันก็ยังไม่ขึ้นอ่ะค่ะ ^^"
คือหนูใช้ ASP.NET version 2.0 เลย download ตัว AJAX Extension มาลงที่ Visual web Developer 2005 Express Edition
หนูต้องลงอาไรเพิ่มหรือป่าว หรือต้องไป Config อาไรที่ไหนมั้ยค่ะ
|
 |
 |
 |
 |
Date :
2010-02-23 16:05:29 |
By :
ladyjupz |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
แก้ปัญหา ได้แล้วค่ะๆ โค๊ด ทั้งหมดถูกแล้ว ค่ะ แค่
ตอนตั้งโปรเจค ให้เลือก AJAX Enable website ค่ะ ยังไงก้อขอบคุณอีกครั้งค่ะ
|
 |
 |
 |
 |
Date :
2010-02-23 20:18:14 |
By :
ladyjupz |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|