RadListView: Set tekst of label control on a GroupTemplate

2 posts, 0 answers
  1. Maurice
    Maurice avatar
    1 posts
    Member since:
    Oct 2011

    Posted 18 Oct 2011 Link to this post




    <telerik:RadListView ID="RadListView3" runat="server" OnLayoutCreated="OnLayoutCreated" ItemPlaceholderID="ProductsContainerItems" OnItemCommand="RadListViewItemCommand" GroupPlaceholderID="GroupsProductsContainer" GroupItemCount="4">


        <asp:PlaceHolder ID="GroupsProductsContainer" runat="server" />



        <fieldset style="float: left; width: auto; border-width:1px; border-color:Gray; ">

        <legend><asp:Label ID="lblLegendDag" runat="server" Text="Maurice"></asp:Label></legend>

        <div id="contentproducts">

            <asp:PlaceHolder ID="ProductsContainerItems" runat="server" />




    How can I set the label lblLegendDag which is in the GroupTemplate.
    I tried this with the following code, but this is not working.


    Label test = (Label)RadListView3.FindControl("lblLegendDag");

    The result is that test delivers null.

    Can someone helps me with this problem.



  2. Iana Tsolova
    Iana Tsolova avatar
    3388 posts

    Posted 21 Oct 2011 Link to this post

    Hi Maurice,

    There are two ways to access the controls in the GroupItemTemplate:
        - Handle the ItemCreated event and implement your logic in the below if statement. See the below sample:
    protected void RadListView1_ItemCreated(object sender, RadListViewItemEventArgs e)
        if (e.Item is RadListViewGroupItem)
            Label lbl = (e.Item as RadListViewGroupItem).FindControl("Label1") as Label;

        - Having a reference to any RadListViewDataItem, you can use the Parent property to access the RadListViewGroupItem and find the control in it:
    RadListViewGroupItem groupItem = RadListView1.Items[0].Parent as RadListViewGroupItem;
    Label lbl = groupItem.FindControl("Label1") as Label;

    All the best,
    Iana Tsolova
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
Back to Top