gfrizzle
gfrizzle

Reputation: 12609

Hide a table column in a nested ListView

I have a ListView inside another ListView, and I'd like to hide a table column in the inner ListView whenever a particular parameter is passed. Given the setup below, how would I hide the ID column (both the header and the data) if the URL contains "...?id=no"?

<asp:ListView ID="ProcedureListView" runat="server">
    <LayoutTemplate>
        <asp:PlaceHolder ID="itemPlaceHolder" runat="server" />
    </LayoutTemplate>
    <ItemTemplate>
        <h4>
            <%#Eval("PROCEDURE_CODE") %>
        </h4>
        <asp:ListView ID="BenefitListView" runat="server" DataSource='<%#Eval("benefits") %>'>
            <LayoutTemplate>
                <table cellpadding="5" class="indent">
                    <tr class="tableHeader">
                        <td>
                            ID
                        </td>
                        <td>
                            Benefit
                        </td>
                    </tr>
                    <asp:PlaceHolder ID="itemPlaceHolder" runat="server" />
                </table>
            </LayoutTemplate>
            <ItemTemplate>
                <tr>
                    <td>
                        <%#Eval("benefit_id")%>
                    </td>
                    <td>
                        <%#Eval("benefit_name")%>
                    </td>
                </tr>
            </ItemTemplate>
        </asp:ListView>
    </ItemTemplate>
</asp:ListView>

Upvotes: 1

Views: 4264

Answers (4)

Victor
Victor

Reputation: 4721

if you are trying to do this from the code behind then you could do this:

On the onBind event for the outer ListView you would find the inner listview control, and then find the label you want and change the visible property to false. i answered this on your other question.

good luck!

Upvotes: 2

rams
rams

Reputation: 6801

add a css class to the HTML tags and from code behind inject the css class onto the page like so

<td id='' class='hideMe'> 
    ID
</td>

code behind, in the pre-render event

if(id==123){
   // please refer to help file for exact syntax
   // but essentially you will be injecting
   // <style type='text/css'>
   // .hideMe{display:none;}
   // </style>
}

Alternatively, you can include the above css class in your stylesheet and only add it to the tags you want hidden based on the ID

Upvotes: 0

Victor
Victor

Reputation: 4721

you could do the following:

<% if (Request.QueryString["id"] != "no") { %>
   <td>
     <%#Eval("benefit_id")%>
   </td>
<% } %>
   <td>
     <%#Eval("benefit_name")%>
   </td>

and do the same for the header.

edit: you are not clear but from a previous comment, if you want to do this in the code behind then you should place the id header and the id data in a label server control. then you can check the query string in the code behind, and on data bind you could set the visible property to false.

there are a few options here, it really depends on what you are most comfortable with.

Upvotes: 0

flesh
flesh

Reputation: 23935

you could wrap them in a placeholder and then dynamically set the visibility of the placeholder to remove the column... (you will need two placeholders)

Upvotes: 1

Related Questions