Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Here's another solution that I just did, seeing that I understand what you want to do:</p> <p><strong>Here's your ASCX / ASPX</strong></p> <pre><code> &lt;asp:ListView ID="ListView1" runat="server" DataSourceID="MyDataSource" ItemPlaceholderID="itemPlaceHolder" OnDataBound="ListView1_DataBound"&gt; &lt;LayoutTemplate&gt; &lt;table border="1"&gt; &lt;tr&gt; &lt;td&gt;Name&lt;/td&gt; &lt;td&gt;Age&lt;/td&gt; &lt;td runat="server" id="tdIsSuperCool"&gt;IsSuperCool&lt;/td&gt; &lt;/tr&gt; &lt;asp:PlaceHolder ID="itemPlaceHolder" runat="server" /&gt; &lt;/table&gt; &lt;/LayoutTemplate&gt; &lt;ItemTemplate&gt; &lt;tr&gt; &lt;td&gt;&lt;%# Eval("Name") %&gt;&lt;/td&gt; &lt;td&gt;&lt;%# Eval("Age") %&gt;&lt;/td&gt; &lt;td runat="server" id="myCol" visible='&lt;%# (bool)Eval("IsSuperCool") %&gt;'&gt;true&lt;/td&gt; &lt;/tr&gt; &lt;/ItemTemplate&gt; &lt;/asp:ListView&gt; &lt;asp:ObjectDataSource ID="MyDataSource" runat="server" DataObjectTypeName="BusinessLogicLayer.Thing" SelectMethod="SelectThings" TypeName="BusinessLogicLayer.MyObjectDataSource" /&gt; </code></pre> <p><strong>Here's the code behind</strong></p> <pre><code>/// &lt;summary&gt; /// Handles the DataBound event of the ListView1 control. /// &lt;/summary&gt; /// &lt;param name="sender"&gt;The source of the event.&lt;/param&gt; /// &lt;param name="e"&gt;The &lt;see cref="System.EventArgs"/&gt; instance containing the event data.&lt;/param&gt; protected void ListView1_DataBound(object sender, EventArgs e) { ListView1.FindControl("tdIsSuperCool").Visible = false; } </code></pre> <p>Do whatever you want in the databound. Because the column is now runat server, and you're handling the DataBound of the control, when you do ListView1.FindControl("tdIsSuperCool") you're in the Layout template so that works like a champ.</p> <p>Put whatever business logic that you want to control the visibility of the td and you're good.</p>
 

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