How to access a label inside a footer template

4 posts, 0 answers
  1. William
    William avatar
    13 posts
    Member since:
    Oct 2018

    Posted 06 Nov 2018 Link to this post

    I have  an asp label inside a footer template as follows:

    <telerik:RadGrid RenderMode="Lightweight" runat="server" ID="RadGrid1" ShowFooter="true">
        <MasterTableView AutoGenerateColumns="false" TableLayout="Fixed">
            <Columns>
                <telerik:GridTemplateColumn DataType="System.Int32" SortExpression="PortalLoadSeconds" HeaderButtonType="TextButton" HeaderStyle-Width="14%" HeaderText="Portal Load Seconds" AutoPostBackOnFilter="true">
                    <ItemTemplate>
                        <%#String.Format("{0}", Eval("PortalLoadSeconds")) %>
                    </ItemTemplate>
                    <FooterTemplate>
                        <asp:Label ID="lbl_TotalSeconds" runat="server"></asp:Label>
                    </FooterTemplate>
                </telerik:GridTemplateColumn>
            </Columns>
        </MasterTableView>
    </telerik:RadGrid>

     

    How do I access the "lbl_TotalSeconds" label in a vb sub to change its text

  2. Tsvetomir
    Admin
    Tsvetomir avatar
    150 posts

    Posted 07 Nov 2018 Link to this post

    Hi William,

    Accessing controls can be done using different events (Load, ItemCreated, ItemDataBound, PreRender, etc..), hence you will need the choose the one that best fits your requirements.  Here is one example of accessing the label inside the Footer item using the PreRender event of RadGrid.
    Protected Sub RadGrid1_PreRender(ByVal sender As Object, ByVal e As EventArgs)
        Dim footer As GridFooterItem = TryCast(RadGrid1.MasterTableView.GetItems(GridItemType.Footer)(0), GridFooterItem) 

        Dim lbl As Label = TryCast(footer.FindControl("lbl_TotalSeconds"), Label)
        lbl.Text = "Modified Footer Text"
    End Sub

    You can learn more about accessing controls, cells, cell values in the Accessing Cells and Rows documentation article.
      
    Should you need further assistance, feel free to contact me back.

    Kind regards,
    Tsvetomir
    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.
  3. William
    William avatar
    13 posts
    Member since:
    Oct 2018

    Posted 07 Nov 2018 in reply to Tsvetomir Link to this post

    Thank you for the quick reply Tsvetomir,

    I can't seem to figure out how to do this in the RadGrid1_NeedDataSource  sub though.  It seems that MasterTableView doesn't have any items at this sub.  Can you help me with it?

     

    Thanks again,

    William

  4. Tsvetomir
    Admin
    Tsvetomir avatar
    150 posts

    Posted 09 Nov 2018 Link to this post

    Hi William,

    The NeedDataSource event is part of the Advanced data binding of the RadGrid control. In the event handler, the data is retrieved either from a service or created in the code-behind and is set to the DataSource of the grid. Afterward, use the DataField property to specify the data field that should be used for the specific column. 

    Check out the following article which puts more insight on the matter:

    Advanced Data-binding (Using NeedDataSource Event)

    The difference between Simple and Advanced data binding could be inspected in the live demo below:

    Simple Vs Advanced Data Binding

    I hope this clarification would prove helpful. Let me know if you need further information.


    Best regards,
    Tsvetomir
    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