gpt4 book ai didi

asp.net - 显示和隐藏中继器中的特定列?

转载 作者:行者123 更新时间:2023-12-02 16:15:47 25 4
gpt4 key购买 nike

我有一个中继器。我想隐藏和显示特定条件的特定列。我有三种类型的主题,它们的 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>

最佳答案

如果(主题)项目 ID 为 2,您可以捕获转发器的 OnItemDataBound 事件并隐藏该列。

为了获得对该列的引用,请将其设为服务器控件:

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

然后在转发器事件中,您可以简单地查找控件并将其隐藏:

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;
}
}
}

请注意,这只是一个简化的示例,您应该开始使用。

关于asp.net - 显示和隐藏中继器中的特定列?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8136451/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com