我有一个名为“ UserControl_Attachments”的用户控件。
<%@ Register TagPrefix="UserControl_Attachments" TagName="Attachments" Src="/UserControls/UserControl_Attachments.ascx" %>
<UserControl_Attachments:Attachments ID="Attachments_Bulletin" runat="server" />
在用户控件中,我有一个telerik:RadListView,在“ ItemTemplate”中,我有一个ID为“ UC_DeleteAttachment_Button”的telerik:RadButton。根据用户从背后的代码登录,我想隐藏按钮。
<telerik:RadListView runat="server" ID="UC_CurrentAttachments" AllowPaging="true" PageSize="40" OnNeedDataSource="UC_CurrentAttachments_NeedDataSource">
<LayoutTemplate>
<div style="max-width: 800px">
<asp:Panel ID="itemPlaceholder" runat="server">
<table>
</table>
</asp:Panel>
</div>
</LayoutTemplate>
<ItemTemplate>
<tr>
<td>
<a href="<%# Eval("AttachmentPath") %>" target="_blank">
<img src="<%# Eval("ImagePath") %>" width="<%# Eval("DisplayWidth") %>" height="<%# Eval("DisplayHeight") %>" />
</a>
</td>
<td>
<asp:Label runat="server" ID="Label_AttachmentName" Text='<%# Eval("DisplayName") %>' Font-Size="10px" />
</td>
<td>
<telerik:RadButton ID="UC_DeleteAttachment_Button" Width="25" runat="server" OnClick="UC_DeleteAttachment_Click" OnClientClicking="UC_Attachment_DeleteConfirm">
<Icon PrimaryIconCssClass="rbRemove"></Icon>
</telerik:RadButton>
</td>
</tr>
<asp:HiddenField ID="HiddenField_AttachmentPath" runat="server" Value='<%# Eval("AttachmentPath") %>' />
</ItemTemplate>
</telerik:RadListView>
这是我后面的代码:
var CurrentAttachment_UC = (RadListView)Attachments_Bulletin.FindControl("UC_CurrentAttachments");
var CurrentAttachmentDeleteButton = (RadButton)CurrentAttachment_UC.FindControl("UC_DeleteAttachment_Button");
if (CurrentAttachmentDeleteButton != null)
CurrentAttachmentDeleteButton.Visible = false;
我已经尝试了几件事,但仍然找不到控件。始终为空。无论如何,我可以隐藏按钮吗?提前致谢。
答案 0 :(得分:0)
在RadListView中查找控件的最佳实践是对RadListView使用ItemCreated事件或ItemDataBound事件:
Protected Sub RadListView1_ItemCreated(sender As Object, e As RadListViewItemEventArgs) Handles RadListView1.ItemCreated
If TypeOf e.Item Is RadListViewItem Then
Dim btn As RadButton= CType(e.Item.FindControl("UC_DeleteAttachment_Button"), RadButton)
btn.Disabled = True
End If
End Sub