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

How to access a label inside a footer template

3 Answers 109 Views
Grid
This is a migrated thread and some comments may be shown as answers.
William
Top achievements
Rank 1
William asked on 06 Nov 2018, 10:14 PM

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

3 Answers, 1 is accepted

Sort by
0
Tsvetomir
Telerik team
answered on 07 Nov 2018, 05:19 PM
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.
0
William
Top achievements
Rank 1
answered on 07 Nov 2018, 10:47 PM

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

0
Tsvetomir
Telerik team
answered on 09 Nov 2018, 04:48 PM
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.
Tags
Grid
Asked by
William
Top achievements
Rank 1
Answers by
Tsvetomir
Telerik team
William
Top achievements
Rank 1
Share this question
or