如何通过asp.net技术巧妙隐藏repeater控件中的特定列?

2026-03-30 12:051阅读0评论SEO基础
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计633个文字,预计阅读时间需要3分钟。

如何通过asp.net技术巧妙隐藏repeater控件中的特定列?

在ASP的Repeater中隐藏一列,最佳做法是通过CSS隐藏服务器端,而不仅仅是HTML。开发者有一个ID,但难以在调试器中找到对应的表。考虑到开发者如何工作,不确定这是否可行。我给HTML表添加了ID。

如何通过asp.net技术巧妙隐藏repeater控件中的特定列?

我需要在asp:repeater中隐藏一列.最好是通过CSS隐藏服务器端,而不仅仅是 HTML.转发器有一个ID,但我很难找到它在调试器中拥有的表.考虑到转发器如何工作,我不确定它是否可行.我给HTML表一个ID,并将其设置为runat =“server”,但它出错了

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”的第一列被设置为隐藏

本文共计633个文字,预计阅读时间需要3分钟。

如何通过asp.net技术巧妙隐藏repeater控件中的特定列?

在ASP的Repeater中隐藏一列,最佳做法是通过CSS隐藏服务器端,而不仅仅是HTML。开发者有一个ID,但难以在调试器中找到对应的表。考虑到开发者如何工作,不确定这是否可行。我给HTML表添加了ID。

如何通过asp.net技术巧妙隐藏repeater控件中的特定列?

我需要在asp:repeater中隐藏一列.最好是通过CSS隐藏服务器端,而不仅仅是 HTML.转发器有一个ID,但我很难找到它在调试器中拥有的表.考虑到转发器如何工作,我不确定它是否可行.我给HTML表一个ID,并将其设置为runat =“server”,但它出错了

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”的第一列被设置为隐藏