显示和隐藏中继器中的特定列?
我有一个复读机。我想隐藏和显示特定条件的特定列。我有三种类型的主题,它们的 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>
I have a repeater. And i want to hide and display a particular column for a particular condition. I have three types of subjects and their ids are 0,1,2 respectively. Now i want to show that particular column when the subject will be 2 only..
My code is :-
<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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果(主题)项 id 为 2,您可以捕获转发器的 OnItemDataBound 事件并隐藏该列。
为了获得对该列的引用,请将其设为服务器控件:
然后在转发器事件中您可以简单地查看控件并隐藏它:
请注意,这只是一个简化的示例,您应该开始使用。
You could catch the OnItemDataBound event of the repeater and hide the column there if the (subject) item id is 2.
In order you can get a reference to the column, make it a server control:
Then in the repeater event you can simply look for the control and hide it:
Please note, this is just a simplified example which should you get started.
我认为您应该首先使用
和
来定义表格的开始和结束来整理它。您可以通过添加 runat="server" 并为列
提供 id 和 runat="server" 属性来让表在服务器上运行,以便您可以针对服务器代码进行编程它。然后,我会根据您的字段值评估绑定单元格的可见属性,或使用 attribute.add("display:none") 或仅使用链接中建议的网格视图。
I think you should start by using
<HeaderTemplate></HeaderTemplate>
and<FooterTemplate></FooterTemplate>
to define the start and end of your table just to tidy it up.You can get the table to run on the server by adding a runat="server" and give the column
<td>
an id and a runat="server" attribute so you can program server code against it. I'd then eval bind the visible attribute of the cell based on your field value or use attributes.add("display:none") or just use a grid view as suggested in the link.