2010-02-13 3 views
0

코드 뒤에서 역할을 기반으로 ListView의 열을 숨기려고합니다. 여기에 마크 업 및 코드입니다 :뒤에있는 코드에서 ListView 테이블 헤더를 숨기기

<asp:ListView ID="lvTimeSheet" runat="server"> 
    <LayoutTemplate> 
     <table id="TimeSheet"> 
      <thead> 
       <tr> 
        <th id="thDelete" runat="server" Visible='<%# IsAdmin() %>'> 
         Select 
        </th> 
       </tr> 
      </thead> 
      <tbody> 
       <tr id="itemPlaceholder" runat="server" /> 
      </tbody> 
     </table> 
    </LayoutTemplate> 
    <ItemTemplate> 
     <tr> 
      <td> 
       <asp:CheckBox ID="cbMarkAsComplete" runat="server" onclick="selectMe(this)" Text=" &nbsp; Delete" /> 
      </td> 
    </ItemTemplate> 
</asp:ListView> 

리스트 뷰 레이아웃 템플릿에서이 나는 id="thDelete" runat="server" Visible='<%# IsAdmin() %>' 속성이있는 <th>이 있습니다. 코드 뒤에,

Public Function IsAdmin() As Boolean 

    If "user is admin" Then 
     Return True 
    Else 
     Return False 
    End If 

End Function 

하지만 그 열 id = "thDelete"는 항상 볼 수 있습니다. 코드의 일부 조건을 기반으로 열을 숨기는 방법은 무엇입니까? 입력 해 주셔서 감사합니다.

+0

당신에게 긍정적하는 IsAdmin의 함수가 false 값을 반환? – FiveTools

+0

예, 함수를 False 만 반환하도록 변경 했더라도 여전히 볼 수 있습니다. – Narazana

답변

1

속성이 runat = "server"인 태그는 포함 할 수 없습니다. < %%>. 이 시도 :

<asp:ListView ID="lvTimeSheet" runat="server"> 
    <LayoutTemplate> 
     <table id="TimeSheet"> 
      <thead> 
<% If IsAdmin() Then %> 

       <tr> 
        <th id="thDelete" runat="server"> 
         Select 
        </th> 
       </tr> 
<% End If %> 

      </thead> 
      <tbody> 
       <tr id="itemPlaceholder" runat="server" /> 
      </tbody> 
     </table> 
    </LayoutTemplate> 
    <ItemTemplate> 
     <tr> 
      <td> 
       <asp:CheckBox ID="cbMarkAsComplete" runat="server" onclick="selectMe(this)" Text=" &nbsp; Delete" /> 
      </td> 
    </ItemTemplate> 
</asp:ListView> 
0

, 이것을 시도하십시오 :

<LayoutTemplate> 
    <table id="TimeSheet"> 
     <thead> 
      <tr> 
       <th id="thDelete" runat="server" Visible='<%# If(IsAdmin().tostring()="True", "true", "false") %>'> 
        Select 
       </th> 
      </tr> 
     </thead> 
     <tbody> 
      <tr id="itemPlaceholder" runat="server" /> 
     </tbody> 
    </table> 
</LayoutTemplate>` 
관련 문제