Hide table column in nested ListView

I have a ListView inside another ListView and I would like to hide the table column in the inner ListView whenever a specific parameter is passed. Given the setup below, how do I hide the id column (both header and 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>

      

+1


source to share


4 answers


if you are trying to do it from the code behind you can do this:

In the onBind event for the outer ListView, you will find the inner listview control, and then find the shortcut you want and change the visible property to false. I answered this question on a different question.



Good luck!

+2


source


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



+1


source


you can 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 didn't get it, but from the previous comment, if you want to do it in the code behind, you have to put the id header and id data in the label server control. then you can check the query string in the code behind, and when binding the data, you can set the visible property to false.

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

0


source


add the css class to your HTML tags and from the code followed by injecting the css class into the page like

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

      

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 to hide based on the id

0


source







All Articles