Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I set a table row color in my repeater based on the values databound to that row in ASP.NET?
    primarykey
    data
    text
    <p>I have a repeater control:</p> <pre><code> &lt;table style="width: 100%"&gt; &lt;asp:Repeater runat="server" ID="rptOptions" OnItemDataBound="rptOptions_ItemDataBound"&gt; &lt;HeaderTemplate&gt; &lt;tr&gt; &lt;td class="GridHeader"&gt;Account&lt;/td&gt; &lt;td class="GridHeader"&gt;Margin&lt;/td&gt; &lt;td class="GridHeader"&gt;Symbol&lt;/td&gt; &lt;td class="GridHeader"&gt;Price&lt;/td&gt; &lt;/tr&gt; &lt;/HeaderTemplate&gt; &lt;ItemTemplate&gt; &lt;tr&gt; &lt;td class="GridRow"&gt;&lt;asp:Label runat="server" ID="lblOptionAccount"&gt;&lt;/asp:Label&gt;&lt;/td&gt; &lt;td class="GridRow"&gt;&lt;asp:Label runat="server" ID="lblOptionMargin"&gt;&lt;/asp:Label&gt;&lt;/td&gt; &lt;td class="GridRow"&gt;&lt;asp:Label runat="server" ID="lblOptionSymbol"&gt;&lt;/asp:Label&gt;&lt;/td&gt; &lt;td class="GridRow"&gt;&lt;asp:Label runat="server" ID="lblOptionPrice"&gt;&lt;/asp:Label&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/ItemTemplate&gt; &lt;/asp:Repeater&gt; &lt;/table&gt; </code></pre> <p>And the following code-behind databound method:</p> <pre><code>protected void rptOptions_ItemDataBound(object sender, RepeaterItemEventArgs e) { if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { Option rowOption = (Option)e.Item.DataItem; ((Label)e.Item.FindControl("lblOptionAccount")).Text = rowOption.Account; ((Label)e.Item.FindControl("lblOptionMargin")).Text = rowOption.Margin ? "Y" : "N"; ((Label)e.Item.FindControl("lblOptionSymbol")).Text = rowOption.Symbol; ((Label)e.Item.FindControl("lblOptionPrice")).Text = rowOption.Price.ToString("C", currencyFormat); } } </code></pre> <p>There are more columns in that grid, but I've slimmed it down just for the question.</p> <p>Now, what I would like to do is change the tr's background color based on the price amount. If it is within different levels, I would like to change the rows background color correspondingly.</p> <p>Do I have to do this with javascript or is there some way I can get access to the table rows in the code-behind to set this color?</p>
    singulars
    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.
 

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