New to Telerik UI for ASP.NET AJAX? Download free 30-day trial

Accessing Controls

Accessing controls in the LayoutTemplate

To get reference to a control in RadListView LayoutTemplate you can use its FindControl(controlId) method.

protected void RadListView1_PreRender(object sender, EventArgs e)
{
    Label lbl = RadListView1.FindControl("Label1") as Label;
}
Protected Sub RadListView1_PreRender(ByVal sender As Object, ByVal e As EventArgs)
    Dim lbl As Label = TryCast(RadListView1.FindControl("Label1"), Label)
End Sub

Accessing controls in the ItemTemplate

To access a control in RadListView item you can handle the ItemCreated event as shown below:

protected void RadListView1_ItemCreated(object sender, RadListViewItemEventArgs e)
{
    if (e.Item is RadListViewDataItem)
    {
        Label label = e.Item.FindControl("Label1") as Label;
    }
}
Protected Sub RadListView1_ItemCreated(ByVal sender As Object, ByVal e As RadListViewItemEventArgs)
    If TypeOf e.Item Is RadListViewDataItem Then
        Dim label As Label = TryCast(e.Item.FindControl("Label1"), Label)
    End If
End Sub

Accessing controls in the EditItemTemplate/InsertItemTemplate

If the RadListView item is in edit mode you can get reference to the respective RadListViewEditableItem instance and call the FindControl(controlId) method for it.

protected void RadListView1_ItemCreated(object sender, RadListViewItemEventArgs e)
{
    if (e.Item is RadListViewEditableItem && e.Item.IsInEditMode)
    {
        TextBox myControl = e.Item.FindControl("TextBox1") as TextBox;
    }
}
Protected Sub RadListView1_ItemCreated(ByVal sender As Object, ByVal e As RadListViewItemEventArgs)
    If TypeOf e.Item Is RadListViewEditableItem AndAlso e.Item.IsInEditMode Then
        Dim myControl As TextBox = TryCast(e.Item.FindControl("TextBox1"), TextBox)
    End If
End Sub

If the RadListView item is in insert mode you can reference the control the same way as in edit mode.

protected void RadListView1_ItemCreated(object sender, RadListViewItemEventArgs e)
{
    if (e.Item is RadListViewInsertItem && e.Item.IsInEditMode)
    {
        TextBox myControl = e.Item.FindControl("TextBox1") as TextBox;
    }
}
Protected Sub RadListView1_ItemCreated(ByVal sender As Object, ByVal e As RadListViewItemEventArgs)
    If TypeOf e.Item Is RadListViewInsertItem AndAlso e.Item.IsInEditMode Then
        Dim myControl As TextBox = TryCast(e.Item.FindControl("TextBox1"), TextBox)
    End If
End Sub
In this article