The AsyncRepeater gives you the ability to create fast data bound templates that are Async-Enabled.
<%@ Register Assembly="AsyncControls" Namespace="DelvingWare.AsyncControls" TagPrefix="dw" %> <dw:AsyncRepeater ID="rptUsers" runat="server" OnItemDataBound="rptUser_ItemDataBound" EnableEffects="true" RollACssClass="rollA" RollBCssClass="rollB" HighlightCssClass="highlight" CssClass="asyncRep" Visible="true"> <HeaderTemplate> <table cellpadding="4"> <tr class="headlnk"> <td> First Name </td> <td> Last Name </td> <td> Account Balance </td> </tr> </HeaderTemplate> <ItemTemplate> <tr $roll$ $highlight$> <td> <dw:AsyncLiteral runat="server" ID="ltlFirstName" /> </td> <td> <dw:AsyncLiteral runat="server" ID="ltlLastName" /> </td> <td> <dw:AsyncLiteral runat="server" ID="ltlAccBalance" /> </td> </tr> </ItemTemplate> <FooterTemplate> </table> </FooterTemplate> </dw:AsyncRepeater> <br /> <dw:AsyncButton runat="server" ID="btMain" OnClick="btMain_Click" CssClass="greyButton">Re-Bind the AsyncRepeater</dw:AsyncButton>
using System; using DelvingWare.AsyncControls; ... protected void Page_Load( object sender, EventArgs e ) { // bind the AsyncRepeater during initial page laod if ( !IsPostBack ) rptUsers.DataBind(dwconn.GetUsers("SELECT TOP 20 * FROM ac_Users ORDER BY newId()")); } protected void rptUser_ItemDataBound( object sender, AsyncRepeaterItemEventArgs ae ) { DWConnection.AccUsers user = (DWConnection.AccUsers)ae.Item.DataItem; // get a reference to the AsyncLiterals AsyncControl ltlLastName = ae.Item["ltlLastName"]; AsyncControl ltlFirstName = ae.Item["ltlFirstName"]; AsyncControl ltlAccBalance = ae.Item["ltlAccBalance"]; // update the text of the AsyncLiterals ltlFirstName.Text = user.firstName; ltlLastName.Text = user.lastName; ltlAccBalance.Text = "$"+user.accBalance; } protected void btMain_Click( object sender, AsyncEventArgs ae ) { // re-bind the AsyncRepeater with random rows/results rptUsers.DataBind(dwconn.GetUsers("SELECT TOP 20 * FROM ac_Users ORDER BY newId()")); }
Imports System Imports DelvingWare.AsyncControls ... Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) ' bind the AsyncRepeater during initial page laod If Not IsPostBack Then rptUsers.DataBind(dwconn.GetUsers("SELECT TOP 20 * FROM ac_Users ORDER BY newId()")) End If End Sub Protected Sub rptUser_ItemDataBound(ByVal sender As Object, ByVal ae As AsyncRepeaterItemEventArgs) Dim user As DWConnection.AccUsers = CType(ae.Item.DataItem,DWConnection.AccUsers) ' get a reference to the AsyncLiterals Dim ltlLastName As AsyncControl = ae.Item("ltlLastName") Dim ltlFirstName As AsyncControl = ae.Item("ltlFirstName") Dim ltlAccBalance As AsyncControl = ae.Item("ltlAccBalance") ' update the text of the AsyncLiterals ltlFirstName.Text = user.firstName ltlLastName.Text = user.lastName ltlAccBalance.Text = ("$" + user.accBalance) End Sub Protected Sub btMain_Click(ByVal sender As Object, ByVal ae As AsyncEventArgs) ' re-bind the AsyncRepeater with random rows/results rptUsers.DataBind(dwconn.GetUsers("SELECT TOP 20 * FROM ac_Users ORDER BY newId()")) End Sub
.asyncRep { margin-top: 20px; font-family: Verdana, Arial, Serif; width: 285px; } .asyncRep span { font-size: 8pt; } .asyncRep .headlnk { font-size: 8pt; font-weight: bold; color: White; background-color: #777; } .asyncRep .rollA { background-color: #eee; } .asyncRep .rollB { background-color: #ddd; } .asyncRep .highlight { background-color: #777; color: White; }