RadListView FindControl

7 posts, 1 answers
  1. oprisan tudorel
    oprisan tudorel avatar
    5 posts
    Member since:
    Mar 2010

    Posted 22 Jul 2010 Link to this post

    Hello!

    I have again, a problem with the RadListView Control. This time, it looks pretty simple but i don't understand why id doesn't work.
    So, to be short this is the problem:

    I have a Radlistview, and in the ItemTemplate, i have all sort of things, labels, updatePanels, tables, etc. The RadListView works fine, but when i try to acces ANY element inside using
    Dim Label1 as New Label = DirectCast(RadListView1.FindControl("LabelID_Here"), Label)
    I get Label as Nothing, or any other elements for that matter.  Trust me i have tried different ways to access the controls but none succeeded(I also tried TryCast, and other methods suggested on the web).
    The problem is that i try to update a panel wich is inside the RadListView, and i can't find it. From what i have seen the FindControl Method only works on RadListView related events such as ItemDataBound, preRender and so on. The problem is that i need the panel to update every 10 seconds or so, so this is unacceptable. 

    What is the solution to accessing different controls inside the RadListView ?

    Thank you,

    and hope for a quick reply,

    Tudorel.
  2. Nikolay Rusev
    Admin
    Nikolay Rusev avatar
    2284 posts

    Posted 23 Jul 2010 Link to this post

    Hello Tudorel,

    If I understand your scenario correctly the controls are places in ItemTemplate of RadListView. If this is the case you should use FindControl in context of RadListViewItem, i.e <RadListViewItem instance>.FindControl(control id).

    Regards,
    Nikolay
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. oprisan tudorel
    oprisan tudorel avatar
    5 posts
    Member since:
    Mar 2010

    Posted 23 Jul 2010 Link to this post

    Can u please provide an example?

    Let's asume this situation.

    <form id="form1" runat="server">
        <div>
            <telerik:RadListView ID="RadListView1" runat="server" DataSourceID="source">
            <ItemTemplate>
            <asp:Label ID="test_label" runat="server" Text='<%#Eval("FirstID") %>'></asp:Label>
            <asp:UpdatePanel ID="updatePanel1" runat="server" >
            <ContentTemplate>
            <asp:Label ID="x" runat="server" Text='<%#Eval ("SecondID") %>' />
            </ContentTemplate>
            </asp:UpdatePanel>
            </ItemTemplate>
            </telerik:RadListView>
            <asp:SqlDataSource ID="SqlDataSource1" runat="server"
                ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
                SelectCommand="SELECT * FROM [IdLIst] WHERE ([Published] = @Published)">
                <SelectParameters>
                    <asp:Parameter DefaultValue="True" Name="Published" Type="Boolean" />
                </SelectParameters>
            </asp:SqlDataSource>
        </div>
        </form>

    And the code behind:

    Partial Class Test_radlistView
        Inherits System.Web.UI.Page
     
        Public Function DoSomething(ByVal Str As String) As Boolean
     
            'How do i access Label and update panel from here, assuming the datasource brings back several items
            Return Str
        End Function
     
    End Class

    So how do i access the controls inside? Because it's still unclear to me.
  5. Nikolay Rusev
    Admin
    Nikolay Rusev avatar
    2284 posts

    Posted 28 Jul 2010 Link to this post

    Hello Tudorel,

    I am attaching sample project demonstrating how you can access and change value of control within ItemDataBound event.

    Nikolay
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  6. oprisan tudorel
    oprisan tudorel avatar
    5 posts
    Member since:
    Mar 2010

    Posted 28 Jul 2010 Link to this post

    As i wrote before i know how to acces the  control from within the itemdatabound event. What i need to know is how to do it outside any Listview events.  How do i acces the elements during a button function, or at page load?
  7. Answer
    Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 29 Jul 2010 Link to this post

    Hello,

    Try the following code snippet in external event to access controls in Itemtemplate of RadListView.

    VB.Net:
    Protected Sub Button1_Click(sender As Object, e As EventArgs)
        For Each item As RadListViewDataItem In RadListView1.Items
            Dim lb As Label = DirectCast(item.FindControl("test_label"), Label)
            'accessing Label
                'accessing UpdatePanel
            Dim panel As UpdatePanel = DirectCast(item.FindControl("updatePanel1"), UpdatePanel)
        Next
    End Sub

    Thanks,
    Princy.
  8. Diptesh
    Diptesh avatar
    2 posts
    Member since:
    Nov 2010

    Posted 15 Feb 2011 Link to this post

    thanx
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017