2011-11-15 25 views
3

我有一箇中繼器。我想隱藏並顯示特定條件的特定列。我有三種類型的主題,他們的ID分別是0,1,2。現在我想表明,特定的列時拍攝對象的只有2 ..顯示並隱藏直放站中的特定列?

我的代碼是: -

<table id="table1" class="yui" cellpadding="0" cellspacing="0"> 
       <thead> 
        <tr> 
         <th> 
          <a href='#' title="Click Header to Sort">EmpID #</a> 
         </th> 
<th>Edit</th> 

        </tr> 
       </thead> 
       <tbody> 
        <asp:Repeater ID="Repaddressorbbl" runat="server" OnItemCommand="Repaddressorbbl_ItemCommand"> 
         <ItemTemplate> 

          <tr id="gh" style="cursor: pointer" onclick="Select(this);"> 
           <td style="text-align: center;"> 
            <%#Eval("empid")%> 
           </td> 
<td> 
            <asp:LinkButton ID="lknumber" runat="server" Text="Edit" CommandName="subjectid" /> 
           </td>        
          </tr> 
         </ItemTemplate> 
        </asp:Repeater> 
       </tbody> 
       <tfoot> 

       </tfoot> 
      </table> 
+0

檢查這一項:http://stackoverflow.com/questions/6051483/is-it-possible-to-hide-a-column-in-an-asprepeater –

回答

3

我想你應該使用<HeaderTemplate></HeaderTemplate><FooterTemplate></FooterTemplate>來定義表的開始和結束只是整理一下啓動。

您可以通過添加runat =「server」來獲取要在服務器上運行的表,併爲列<td>指定一個id和runat =「server」屬性,以便您可以根據該屬性對服務器代碼進行編程。然後,我會根據您的字段值綁定單元格的可見屬性,或者使用attributes.add(「display:none」)或僅使用鏈接中建議的網格視圖。

3

你可以捕捉到中繼器的OnItemDataBound事件和隱藏的列有如果(主題)項目ID爲2

爲了你能得到的列的引用,使服務器控件:

<td style="text-align: center;" id="COL_TO_HIDE" runat="server"><%#Eval("empid")%></td> 

然後在轉發事件中,你可以簡單的廁所K爲控制和隱藏:

protected void YourRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e) 
{ 
    if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) 
    { 
     var subject = (Subject)e.Item.DataItem; 
     if (subject.Id == 2) 
     { 
      var col = e.Item.FindControl("COL_TO_HIDE"); 
      col.Visible = false; 
     } 
    } 
} 

請注意,這僅僅是應該你開始一個簡單的例子。

+0

先生我也想這樣做,但無法找到td ... –

0
<asp:Repeater ID="Repaddressorbbl" runat="server" 
OnItemCommand="Repaddressorbbl_ItemCommand"> 
    <ItemTemplate> 
     <tr id="gh" style="cursor: pointer" onclick="Select(this);"> 
      <td style="text-align: center;"> 
       <%#Eval("empid")%> 
      </td> 
      <% if (false){ %> 
      <td> 
       <asp:LinkButton ID="lknumber" runat="server" 
       Text="Edit" CommandName="subjectid" /> 
      </td> 
      <% } %>        
     </tr> 
    </ItemTemplate> 
</asp:Repeater>