Accessing Controls in RadListView not working

2 posts, 0 answers
  1. Tonyz289
    Tonyz289  avatar
    50 posts
    Member since:
    Jun 2011

    Posted 18 Jul 2011 Link to this post

    Under the RadListView you suggest the following:


    RadControls for ASP.NET AJAX

    Collapse imageAccessing controls in the LayoutTemplate

    To get reference to a control in RadListView LayoutTemplate you can use its FindControl(controlId) method.

    CopyC#
    protected void RadListView1_PreRender(object sender, EventArgs e)
    {
        Label lbl = RadListView1.FindControl("Label1") as Label;
    }
    
    I can't make it work. 
    My code:
    
    <telerik:RadListView ID="RadListView1" runat="server" AllowPaging="True"
        ItemPlaceholderID="PlaceHolder1" onitemcreated="RadListView1_ItemCreated"
        onprerender="RadListView1_PreRender" >
        <LayoutTemplate>
            <asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder>
        </LayoutTemplate>
        <ItemTemplate>
            <div style="float: left;">
                <fieldset style="border: 0; width: 154px; height: 154px; margin: 5px 5px 5px 5px;">
                    <div class="myClass" style="padding: 2px 2px 2px 2px; background: #eeeeee; text-align: center;">
                        <telerik:RadBinaryImage ID="RadBinaryImage1" runat="server" AutoAdjustImageControlSize="False"
                            CssClass="myClass" ImageUrl='<%# Eval("thumbUrl") %>' ResizeMode="Fit" AlternateText="Click to view preview"
                            ToolTip="Click to view preview" Width="150px" Height="150px" />
                    </div>
                </fieldset>
                <div style="border: 0px; white-space: normal; width: 150px; margin: 5px 5px 5px 5px;
                    padding: 2px 2px 2px 2px;">
                    <asp:CheckBox ID="chkImage" runat="server" AutoPostBack="True" />
                    <asp:HyperLink ID="lnkAsset" Target="_blank" NavigateUrl='javascript:void(0);' runat="server"><%# Eval("filename") %></asp:HyperLink>
                    <asp:HiddenField ID="hiddenAssetId" Value='<%# Eval("id") %>' runat="server" />
                </div>
            </div>
        </ItemTemplate>
        <EmptyDataTemplate>
            No Assets Found
        </EmptyDataTemplate>
    </telerik:RadListView>
    Code behind:
    protected void RadListView1_PreRender (object sender, EventArgs e)
    {
        HyperLink lnkAsset = RadListView1.FindControl ("lnkAsset") as HyperLink;
        lnkAsset.Attributes.Add ("OnClick", "javascript:void(assetInfoPopUp(assetId));return false;");
    }
    lnkAsset is null.
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 19 Jul 2011 Link to this post

    Hello Tony,

    In order to access the ItemTemplate control, try the following code snippet.
    C#:
    protected void RadListView1_ItemCreated(object sender, RadListViewItemEventArgs e)
    {
        if (e.Item is RadListViewDataItem)
        {
            Hyperlink lnkAsset = e.Item.FindControl("lnkAsset") as Hyperlink ;
        }
    }

    Thanks,
    Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top