Вопрос

I have browsed the different cases already answered about the topic but did not find the one answering my question:

<asp:ListView ID="lstView_phoneUsersExtensionsFound" runat="server" OnItemDataBound="lstView_phoneUsersExtensionsFound_ItemDataBound">
  <LayoutTemplate>
    <table id="tbl1" runat="server" class="bordered">
      <tr id="tr1" runat="server">
        <th id="th1" runat="server" visible='<%# selectOptionVisible %>' >Select</th>
        <th id="th1" runat="server">UserID</th>
        <th id="th2" runat="server">Firstname</th>
        <th id="th3" runat="server">Lastname</th>
      </tr>
        <tr id="ItemPlaceholder" runat="server">  
      </tr>            
    </table>
  </LayoutTemplate>
  <ItemTemplate>
    <tr>
       <td runat="server" visible='<%# selectOptionVisible %>' >
         <input type="radio" name="rdbutton_userSelection" value='<%# Eval("uuid") %>' />
         <asp:HiddenField runat="server" ID="hdfield_userID" Value='<%# Eval("uuid")%>' />
       </td>
       <td><asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%# String.Format("~/Users/DisplayUserDetails.aspx?selectedCCMUserID={0}&uuid={1}",Eval("userID"),Eval("uuid"))%>'><%# Eval("userID")%></asp:HyperLink></td>
       <td><%# Eval("firstname")%></td>
       <td><%# Eval("lastname")%></td>
     </tr>
   </ItemTemplate>
 <EmptyDataTemplate></EmptyDataTemplate></asp:ListView>

The repeater layouttemplate header does not take into account the visible value but the different items work well and hide the cell when needed. I would like to keep using an aspx function and not go through javascript or CSS if possible. Any idea?

Это было полезно?

Решение

Well the below code does the trick but I am sure there should be a better way.

  protected void lstView_phoneUsersExtensionsFound_ItemDataBound(object sender, ListViewItemEventArgs e)
{
    HtmlTableCell th_selectColumn = (HtmlTableCell)lstView_phoneUsersExtensionsFound.FindControl("th1");
    th_selectColumn.Visible = selectOptionVisible;

}

Другие советы

Try this...

<th id="th1" runat="server" visible='<%# Eval("selectOptionVisible") %>'>

The problem was in visible='<%# selectOptionVisible %>'

Instead I changed it to visible='<%# Eval("selectOptionVisible") %>'

Make sure that your data source contains a column as selectOptionVisible

Note

To hide the column header i.e <th>,

  1. Load the "selectOptionVisible to a variable in the code behind while page loading.

  2. Instead of '<%# Eval("selectOptionVisible") %>'

    now you can use '<%# selectOptionVisibleVariable %>'.

  3. Set value for selectOptionVisibleVariable before loading data to ListView.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top