You can do this by changing the logic in the repeater or by providing data to the relay, which controls the behavior you want. I prefer the repeater to be left without it. If you are familiar with MVC, keep your logic out of sight.
I save space here by using a list as a data source, not a database result, but the principle is the same. You probably have a collection of IDataRecord as a source if you are returning from a database.
using System; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; using System.Collections.Generic; using System.Linq; namespace StackOverflowRepeater { public partial class Default : System.Web.UI.Page { protected override void OnInit(EventArgs e) { repeater.ItemDataBound += HandleRepeaterItemDataBound; var data = new List<string>(); if (!data.Any())
This assumes the following markup:
<%@ Page Language="C#" Inherits="StackOverflowRepeater.Default" %> <html> <body> <form runat="server"> <asp:Repeater id='repeater' runat="server"> <ItemTemplate> <span id='output' runat="server" /> </ItemTemplate> </asp:Repeater> </form> </body> </html>
source share