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

Asp.Net Code behind doesn't recognize ASP control within NestedViewTemplate of RadGrid

6 Answers 250 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jay
Top achievements
Rank 1
Jay asked on 26 Jan 2010, 08:08 PM
I am using the NestedView Template to allow more details to be displayed about an item when it's expanded and would like to use a few dropdown menus and buttons in there, but when I add them and go into my code behind they aren't recognized?

They do not exist in the IDE's listing of page controls for my ASP.NET markup? If I move the control outside of the nestedTableView it appears in that list.

I assume it's because it's wrapped inside the RadGrid, but I am not sure how to reference it.

6 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 26 Jan 2010, 08:33 PM
Hello Jason,

It is not possible to access the nested controls directly since they reside in a naming container. I recommend you try the following approach:
        ...
    <NestedViewTemplate>
        <asp:CheckBox ID="CheckBox1" runat="server" />
    </NestedViewTemplate>
</MasterTableView>

protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
{
    if (e.Item is GridNestedViewItem)
        (e.Item.FindControl("CheckBox1") as CheckBox).BackColor = System.Drawing.Color.Red;
}

For more information:
MSDN How to: Access Members of a Control's Naming Container
Joteke's Blog : Understanding the naming container hierarchy of ASP.NET databound controls

Regards,
Daniel
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Jay
Top achievements
Rank 1
answered on 26 Jan 2010, 09:00 PM
Private Sub RadGrid1_ItemCreated(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles RadGrid1.ItemCreated  
 
        If e.Item = GridNestedViewItem Then  
            (e.Item.FindControl("cboActions") as dropdownlist)  
        End If  
    End Sub 
 Struggling with the codebehind section.
I had VS.NET create the code shell for me and it looks completly different from yours. Basically the only part of this code that is happy is the e.Item, the rest isn't going well.
0
Jay
Top achievements
Rank 1
answered on 26 Jan 2010, 09:47 PM
The goal of mine is to be able to invoke some save routines based on what's selected in the combo box, so I need to be able to catch when the combo option changes and then call the relevant routine from there.
0
Princy
Top achievements
Rank 2
answered on 27 Jan 2010, 07:54 AM
Hello Jason,

Try out the following code to achieve the required:
vb:
Protected Sub RadGrid1_ItemCreated(sender As Object, e As GridItemEventArgs) 
    If TypeOf e.Item Is GridNestedViewItem Then 
        Dim ddl As DropDownList = DirectCast(e.Item.FindControl("cboActions"), DropDownList) 
        ddl.AutoPostBack = True 
        AddHandler ddl.SelectedIndexChanged, AddressOf ddl_SelectedIndexChanged          
    End If 
End Sub 
 
Sub ddl_SelectedIndexChanged(sender As Object, e As EventArgs) 
    Dim strtxt As String = (TryCast(sender, DropDownList)).SelectedItem.Text 
 
End Sub 

Thanks
Princy.
0
Jay
Top achievements
Rank 1
answered on 27 Jan 2010, 03:58 PM
Thanks Princy,
Any chance you can help me take it one step further?

Now that I have that SelectedChanged event working, how can I reference the ID from the row?

I have an action that requires the ID from that selected row that I need to pass in.
thanks
0
Daniel
Telerik team
answered on 01 Feb 2010, 11:42 AM
Hello Jason,

I'm not sure whether ID is the ID of the corresponding row/item or it is a data field in the parent table. Could you please clarify? In the meantime you could try the following:
Sub ddl_SelectedIndexChanged(sender As Object, e As EventArgs)
    Dim ddl As DropDownList = TryCast(sender, DropDownList)
    Dim strtxt As String = ddl.SelectedItem.Text
    Dim nItem As GridNestedViewItem = TryCast(ddl.NamingContainer, GridNestedViewItem)
    Dim itemId As String = nItem.UniqueID
    Dim idCellText As String = nItem.ParentItem("ID").Text
End Sub

Best regards,
Daniel
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
Grid
Asked by
Jay
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Jay
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Share this question
or