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

[Solved] Accessing a control within a NestedViewTemplate?

1 Answer 218 Views
Grid
This is a migrated thread and some comments may be shown as answers.
diggityDawg
Top achievements
Rank 1
diggityDawg asked on 08 May 2008, 03:46 PM
I have a Label within a NestedViewTemplate.  I just want to be able to access this Label from my code so I can populate it when the associated row in clicked.  I was able to get a reference to it for the first row, but there's got to be a better way...  Here's how I'm getting to it from the Grid's OnItemCommand method:
protected void radGridSample_ItemCommand(object sender, GridCommandEventArgs e)  
{  
    if (e.CommandName == "ExpandCollapse")  
    {  
        if (e.Item.Expanded == false)  
        {  
            // The line below is where I get the label, but it's too clunky and only works for on GridItem...  
            Label lblDetail = e.Item.Parent.Controls[4].FindControl("lblDetail"as Label;  
            if (lblDetail != null)  
            {  
                StringBuilder sbDetail = new StringBuilder();  
                sbDetail.AppendLine("<div class='Details'>bla bla bla</div>");  
                lblDetail.Text = sbDetail.ToString();  
            }  
        }  
    }  
}  
 
What's the *right* way to do this?  I couldn't find any mention of it in the docs or samples...

Thanks!

Eddie

1 Answer, 1 is accepted

Sort by
0
diggityDawg
Top achievements
Rank 1
answered on 08 May 2008, 04:30 PM
I managed to get it to work with this:
Label lblDetail = ((GridTableView)e.Item.Parent.Parent).Items[e.Item.ItemIndex].ChildItem.FindControl("lblDetail"as Label; 
Is that the best way to access this control within the NestedTableView?  Please let me know if there's a better way.
Tags
Grid
Asked by
diggityDawg
Top achievements
Rank 1
Answers by
diggityDawg
Top achievements
Rank 1
Share this question
or