Find control in LayoutTemplate

10 posts, 0 answers
  1. Erik Kleinreesink
    Erik Kleinreesink avatar
    10 posts
    Member since:
    Nov 2008

    Posted 01 Feb 2010 Link to this post

    Please telle me how I can find controls in the LayoutTemplate (see attached picture).
    I need to set the text attributes for different languages.

  2. Sebastian
    Admin
    Sebastian avatar
    9934 posts

    Posted 01 Feb 2010 Link to this post

    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.
  3. Erik Kleinreesink
    Erik Kleinreesink avatar
    10 posts
    Member since:
    Nov 2008

    Posted 01 Feb 2010 Link to this post

    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.
  4. slnavn2000
    slnavn2000 avatar
    5 posts
    Member since:
    Nov 2008

    Posted 21 Jun 2010 Link to this post

    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
  5. Kiara
    Kiara avatar
    309 posts
    Member since:
    Jul 2006

    Posted 21 Jun 2010 Link to this post

    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
  6. slnavn2000
    slnavn2000 avatar
    5 posts
    Member since:
    Nov 2008

    Posted 21 Jun 2010 Link to this post

    yeah, I can find control in ItemCreated event

    thanks Kiara very much :)
  7. howard
    howard avatar
    2 posts
    Member since:
    Dec 2018

    Posted 06 May 2019 Link to this post

       <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???

     

  8. Vessy
    Admin
    Vessy avatar
    2330 posts

    Posted 07 May 2019 Link to this post

    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.
  9. howard
    howard avatar
    2 posts
    Member since:
    Dec 2018

    Posted 09 May 2019 in reply to Vessy Link to this post

    Oh my goodness, it's Work!!!!!!!!  I truly appreciate your help!!!
  10. Vessy
    Admin
    Vessy avatar
    2330 posts

    Posted 09 May 2019 Link to this post

    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.
Back to Top