我需要在asp:repeater中隐藏一列.最好是通过CSS隐藏服务器端,而不仅仅是 HTML.转发器有一个ID,但我很难找到它在调试器中拥有的表.考虑到转发器如何工作,我不确定它是否可行.我给HTML表
Unexpected end of file looking for
tag.
我该怎么做?我需要切换到gridview吗?使用gridview,我可以更容易地做到这一点.
<asp:repeater id="repeaterId" runat="server"> <ItemTemplate> <tr> <td><%# DataBinder.Eval(Container.DataItem, "col1")%></td> <td nowrap="nowrap" align="left"><%# DataBinder.Eval(Container.DataItem, "col2")%></font></td> </tr> </ItemTemplate> <AlternatingItemTemplate> <tr> <td><%# DataBinder.Eval(Container.DataItem, "col1")%></td> <td nowrap="nowrap" align="left"><%# DataBinder.Eval(Container.DataItem, "col2")%></td> </AlternatingItemTemplate> <HeaderTemplate> <table id="rPhysicalTable" class="cssTable"> <tr class="aClass"> <th>col1</th> <th>col2</th> </tr> </HeaderTemplate> <FooterTemplate> </table> </FooterTemplate> </asp:repeater>我们可以使用转发器ItemDataBound事件隐藏html表的列
为此,我们指定要隐藏的表格单元格的id,并将单元格标记为runat =“server”
<asp:repeater id="repeaterId" runat="server"> <ItemTemplate> <tr> <td id="tdhideItem" runat="server"><%# DataBinder.Eval(Container.DataItem, "col1")%></td> <td nowrap="nowrap" align="left"><%# DataBinder.Eval(Container.DataItem, "col2")%></font></td> </tr> </ItemTemplate> <AlternatingItemTemplate> <tr> <td id="tdhideAltItem" runat="server"><%# DataBinder.Eval(Container.DataItem, "col1")%></td> <td nowrap="nowrap" align="left"><%# DataBinder.Eval(Container.DataItem, "col2")%></td> </AlternatingItemTemplate> <HeaderTemplate> <table id="rPhysicalTable" class="cssTable"> <tr class="aClass"> <th id="thhideHeader" runat="server">col1</th> <th>col2</th> </tr> </HeaderTemplate> <FooterTemplate> </table> </FooterTemplate> </asp:repeater>
以下vb.net代码被指定为后面的代码
Protected Sub repeaterId_ItemDataBound(sender As Object, e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles repeaterId.ItemDataBound If e.Item.ItemType = ListItemType.Item Then DirectCast(e.Item.FindControl("tdhideItem"), HtmlTableCell).Visible = False End If If e.Item.ItemType = ListItemType.AlternatingItem Then DirectCast(e.Item.FindControl("tdhideAltItem"), HtmlTableCell).Visible = False End If If e.Item.ItemType = ListItemType.Header Then DirectCast(e.Item.FindControl("thhideHeader"), HtmlTableCell).Visible = False End If End Sub
在上面的代码中,表“col1”的第一列被设置为隐藏