0

我有一个名为“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;

我已经尝试了几件事,但仍然找不到控件。它始终为空。无论如何我可以隐藏按钮吗?提前致谢。

4

1 回答 1

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
于 2019-11-29T01:26:32.427 回答