Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You could do this by altering the logic in the repeater or by providing data to the repeater that drives the behavior you want. I prefer that the repeater is left out of it. It's a keep your logic out of the view thing if you are familiar with MVC.</p> <p>I am saving space here by using a List as the data source instead of a database result but the principle is the same. You would probably have a collection of IDataRecord as your source if you are returning from a DB.</p> <pre><code>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&lt;string&gt;(); if (!data.Any()) // could also be data.Count &lt; 1 { data.Add("No Row Found"); } repeater.DataSource = data; repeater.DataBind(); base.OnInit(e); } void HandleRepeaterItemDataBound (object sender, RepeaterItemEventArgs e) { if ((e.Item.ItemType == ListItemType.AlternatingItem) || (e.Item.ItemType == ListItemType.Item)) { var span = (HtmlGenericControl) e.Item.FindControl("output"); span.InnerText = e.Item.DataItem.ToString(); } } } } </code></pre> <p>This is assuming the following mark-up:</p> <pre><code>&lt;%@ Page Language="C#" Inherits="StackOverflowRepeater.Default" %&gt; &lt;html&gt; &lt;body&gt; &lt;form runat="server"&gt; &lt;asp:Repeater id='repeater' runat="server"&gt; &lt;ItemTemplate&gt; &lt;span id='output' runat="server" /&gt; &lt;/ItemTemplate&gt; &lt;/asp:Repeater&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload