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

RadListView FindControl

6 Answers 584 Views
ListView
This is a migrated thread and some comments may be shown as answers.
oprisan tudorel
Top achievements
Rank 1
oprisan tudorel asked on 22 Jul 2010, 05:06 PM
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.

6 Answers, 1 is accepted

Sort by
0
Nikolay Rusev
Telerik team
answered on 23 Jul 2010, 03:54 PM
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
0
oprisan tudorel
Top achievements
Rank 1
answered on 23 Jul 2010, 04:20 PM
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.
0
Nikolay Rusev
Telerik team
answered on 28 Jul 2010, 03:42 PM
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
0
oprisan tudorel
Top achievements
Rank 1
answered on 28 Jul 2010, 04:04 PM
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?
0
Accepted
Princy
Top achievements
Rank 2
answered on 29 Jul 2010, 02:25 PM
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.
0
Diptesh
Top achievements
Rank 1
answered on 15 Feb 2011, 06:46 PM
thanx
Tags
ListView
Asked by
oprisan tudorel
Top achievements
Rank 1
Answers by
Nikolay Rusev
Telerik team
oprisan tudorel
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Diptesh
Top achievements
Rank 1
Share this question
or