This is a migrated thread and some comments may be shown as answers.

RadListView: Set tekst of label control on a GroupTemplate

1 Answer 117 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Maurice
Top achievements
Rank 1
Maurice asked on 18 Oct 2011, 11:03 AM

 

 

 

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

<LayoutTemplate>

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

</LayoutTemplate>

<GroupTemplate>

    <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" />

    </div>

    </fieldset>

</GroupTemplate>

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.

 

 

1 Answer, 1 is accepted

Sort by
0
Iana Tsolova
Telerik team
answered on 21 Oct 2011, 03:00 PM
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
Tags
ListView
Asked by
Maurice
Top achievements
Rank 1
Answers by
Iana Tsolova
Telerik team
Share this question
or