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

Find control in LayoutTemplate

9 Answers 555 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Erik Kleinreesink
Top achievements
Rank 1
Erik Kleinreesink asked on 01 Feb 2010, 10:49 AM
Please telle me how I can find controls in the LayoutTemplate (see attached picture).
I need to set the text attributes for different languages.

9 Answers, 1 is accepted

Sort by
0
Sebastian
Telerik team
answered on 01 Feb 2010, 12:40 PM
Hi Erik,

Merely invoking the FindControl(labelId) method for the RadListView instance should be sufficient to locate the controls inside its layout template. This can be done inside the PageLoad handler of the page, for example:

C#
(RadListView1.FindControl("lblForum") as Label).Text = ....

VB.NET
CType(RadListView1.FindControl("lblForum"), Label).Text = .....


Best regards,
Sebastian
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Erik Kleinreesink
Top achievements
Rank 1
answered on 01 Feb 2010, 12:58 PM
Thank you for your answer.
When I tried it, it didn't work. But I found out it depends on the page event in wich you use this statement.
De control is not yet defined in the page_load event.
When I used it in the RadListView1_PreRender event it worked fine.
0
slnavn2000
Top achievements
Rank 1
answered on 21 Jun 2010, 07:41 AM
Hi All, 

With this code, I could find control in LayoutTemplate,  
protected void RadListView1_PreRender(object sender, EventArgs e)
        {            
            Label lblTest= RadListView1.FindControl("lblTest") as Label;
            lblTest.Text = "Hello";
        }

but, when I using this to find control in EmptyDataTemplate, it return null, I don't know why?!!

Please give me some suggestion!

Thanks, 
slnavn2000
0
Kiara
Top achievements
Rank 1
answered on 21 Jun 2010, 12:27 PM

Listen for the ItemCreated server event of the listview for this purpose. This code worked as expected on my end:

        <asp:ScriptManager ID="ScriptManager1" runat="server" /> 
        <telerik:RadListView ID="RadListView1" DataSourceID="SqlDataSource1" runat="server" 
            ItemPlaceholderID="ProductItemContainer" Skin=""   
            onitemcreated="RadListView1_ItemCreated">  
            <LayoutTemplate> 
                <fieldset id="ProductItemContainer" runat="server" /> 
            </LayoutTemplate> 
            <ItemTemplate> 
                <ul> 
                    <li> 
                        <label> 
                            Product name:</label> 
                        <%#Eval("ProductName")%> 
                    </li> 
                    <li> 
                        <label> 
                            Quantity per unit:</label> 
                        <%#Eval("QuantityPerUnit")%> 
                    </li> 
                    <li> 
                        <label> 
                            Unit price:</label> 
                        <%# DataBinder.Eval(Container.DataItem, "UnitPrice", "{0:C}")%> 
                    </li> 
                    <li> 
                        <label> 
                            Units in stock:</label> 
                        <%#Eval("UnitsInStock")%> 
                    </li> 
                    <li> 
                        <label> 
                            Discontinued:</label> 
                        <%#Eval("Discontinued")%> 
                    </li> 
                </ul> 
            </ItemTemplate> 
            <EmptyDataTemplate> 
                <asp:Label ID="lblEmpty" runat="server" Text="No data" /> 
            </EmptyDataTemplate> 
        </telerik:RadListView> 
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>" 
            ProviderName="System.Data.SqlClient" SelectCommand="SELECT TOP 3 ProductID, ProductName, QuantityPerUnit, UnitPrice, UnitsInStock, Discontinued FROM Products WHERE 1=0" /> 

    protected void RadListView1_ItemCreated(object sender, RadListViewItemEventArgs e)  
    {  
        if (e.Item is RadListViewEmptyDataItem)  
        {  
            Label lbl1 = e.Item.FindControl("lblEmpty"as Label;  
            lbl1.Text = "No data available";  
        }  
    } 

Kiara
0
slnavn2000
Top achievements
Rank 1
answered on 22 Jun 2010, 02:59 AM
yeah, I can find control in ItemCreated event

thanks Kiara very much :)
0
howard
Top achievements
Rank 1
answered on 06 May 2019, 12:49 PM

   <telerik:RadListView ID="RLVTEST" runat="server" RenderMode="Lightweight" ItemPlaceholderID="itemPlaceholder" AllowPaging="True" PageSize="5"
                    DataKeyNames="G,M,GID" ClientDataKeyNames="G,M,GID" OnItemCommand="RLVTEST_ItemCommand" BorderWidth="0px">
                    <LayoutTemplate>
                        <div class="RadListView RadListView_<%# Container.Skin %>" style="border-width: 0px; width: 100%;">
                            <fieldset id="FieldSet1" style="border-width: 0px; width: 100%;">
                                <asp:PlaceHolder ID="itemPlaceholder" runat="server"></asp:PlaceHolder>
                            </fieldset>
                        </div>
                    </LayoutTemplate>
                    <ItemTemplate>
                       
                    </ItemTemplate>
                    <EmptyDataTemplate>
                        <div >
                            <div class="rlvEmpty">
                                <asp:Label ID="LB_MSG" runat="server" Text="no data"></asp:Label>
                            </div>
                        </div>
                    </EmptyDataTemplate>
                </telerik:RadListView>

 

 

How can i  change Label:LB_MSG text from EmptyDataTemplate  Code Behind???

 

0
Vessy
Telerik team
answered on 07 May 2019, 01:11 PM
Hi howard,

Using the approach suggested by Kiara will allow you to change the text of the label as follows:
<telerik:RadListView ID="RLVTEST" runat="server" RenderMode="Lightweight"
    ItemPlaceholderID="itemPlaceholder" AllowPaging="True" PageSize="5"
    DataKeyNames="G,M,GID" ClientDataKeyNames="G,M,GID"
    OnItemCommand="RLVTEST_ItemCommand" BorderWidth="0px"
    OnItemCreated="RadListView1_ItemCreated">
    <LayoutTemplate>
        <div class="RadListView RadListView_<%# Container.Skin %>" style="border-width: 0px; width: 100%;">
            <fieldset id="FieldSet1" style="border-width: 0px; width: 100%;">
                <asp:PlaceHolder ID="itemPlaceholder" runat="server"></asp:PlaceHolder>
            </fieldset>
        </div>
    </LayoutTemplate>
    <ItemTemplate>
    </ItemTemplate>
    <EmptyDataTemplate>
        <div>
            <div class="rlvEmpty">
                <asp:Label ID="LB_MSG" runat="server" Text="no data"></asp:Label>
            </div>
        </div>
    </EmptyDataTemplate>
</telerik:RadListView>
protected void RadListView1_ItemCreated(object sender, RadListViewItemEventArgs e)
{
    var type = e.Item.GetType().FullName;
 
    if (e.Item is RadListViewEmptyDataItem)
    {
        Label lbl1 = e.Item.FindControl("LB_MSG") as Label;
        lbl1.Text = "No data available";
    }
}


Regards,
Vessy
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
howard
Top achievements
Rank 1
answered on 09 May 2019, 10:26 AM
Oh my goodness, it's Work!!!!!!!!  I truly appreciate your help!!!
0
Vessy
Telerik team
answered on 09 May 2019, 12:35 PM
Hi,

You are welcome, howard - I am glad my reply helped you to achieve your goal :)

Regards,
Vessy
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
ListView
Asked by
Erik Kleinreesink
Top achievements
Rank 1
Answers by
Sebastian
Telerik team
Erik Kleinreesink
Top achievements
Rank 1
slnavn2000
Top achievements
Rank 1
Kiara
Top achievements
Rank 1
howard
Top achievements
Rank 1
Vessy
Telerik team
Share this question
or