Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There are may ways to do that, I'm usually using repeater's event OnItemDataBound event that occurs when repeater's item is bound to a data item.</p> <p>To explain OnItemDataBound event let's assume that we have repeater with one field that is always displayed (Name) and optional field that is displayed if is not null (Optional). Further more we want to display some predefined value if optional field is null or empty. <br /> To do this we need first to set repeater's OnItemDataBound event to point to a method, And also to build repeater's item template. We could use any server control within repeater's item template that we can reference later in OnItemDataBound method.</p> <pre><code>&lt;asp:Repeater ID="repeaterResults" runat="server" OnItemDataBound="repeaterResult_ItemDataDataBound"&gt; &lt;ItemTemplate&gt; &lt;strong&gt;&lt;%#Eval("Name") %&gt;&lt;/strong&gt; &lt;asp:Literal runat="server" ID="ltlOption" /&gt; &lt;br /&gt; &lt;/ItemTemplate&gt;&lt;/asp:Repeater&gt; </code></pre> <p>Further let's suppose that we will bind a collection of simple objects that are having two properties :Name and Option like follows:</p> <pre><code>public class SimpleEntity { public string Name {get;set;} public string Option {get;set;} } </code></pre> <p>Next we will implement repeaterResult_ItemDataDataBound method as follows:</p> <pre><code>protected void repeaterResult_ItemDataDataBound(object sender, RepeaterItemEventArgs e) { SimpleEntity ent = e.Item.DataItem as SimpleEntity; Literal ltlOption = e.Item.FindControl("ltlOption") as Literal; if (ent != null &amp;&amp; ltlOption != null) { if (!string.IsNullOrEmpty(ent.Option)) { ltlOption.Text = ent.Option; } else { ltlOption.Text = "Not entered!"; } } } </code></pre> <p>As method above is implemented, we will display optional field if exists, while if optional field is null or empty string we will display predefined string "Not entered!".</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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