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

GridNestedViewItem values

2 Answers 238 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jessica B.
Top achievements
Rank 1
Jessica B. asked on 10 Jun 2015, 08:16 PM

I'm creating a nested view, for which I am using a DataSource different from the main grid. This is working perfectly, I have the whole thing wired up and looking good.

 However, I need to do some stuff on the server side to change what is displayed in the nested view based on some values in the nested view. Simple stuff like if one value is "NO" then don't show a label. I'm able to detect and manipulate the controls in the nested view so far but I am stuck as to how to get the values from the datasource of the nested view.

 I also don't know when to do the hiding/showing of the items. Do I do it OnItemCreated? OnItemCommand? OnNeedDataSource? Right now I am doing it OnItemCreated but I have no idea if that is the right way.

 Here's my datasource, the Nested View settings, and my ItemCreated. Line 13 in the C# is what I know is wrong.

<asp:ObjectDataSource ID="dsViewCredit" runat="server"  
SelectMethod="GetSingleCredit"
            TypeName="ASIGlobalWebSitePublic.AdminPortal.components.AdminCredit">
            <SelectParameters>
                <asp:Parameter Name="ID" Type="Int32" />
            </SelectParameters>
        </asp:ObjectDataSource>

<NestedViewSettings DataSourceID="dsViewCredit">
<ParentTableRelation>
<telerik:GridRelationFields DetailKeyField="ID" MasterKeyField="ID" />
</ParentTableRelation>
</NestedViewSettings>
01.protected void Grid_ItemCreated(object source, GridItemEventArgs e)
02.        {
03.            if (e.Item is GridNestedViewItem)
04.            {
05.                 
06.                GridNestedViewItem gridNestedViewItemObj = e.Item as GridNestedViewItem;
07.                GridDataItem parentItemObj = (e.Item as GridNestedViewItem).ParentItem;
08.                if (gridNestedViewItemObj == null || parentItemObj == null)
09.                    return;
10. 
11.                if (gridNestedViewItemObj.OwnerTableView.DataKeyValues != null)
12.                {
13.                    string BillingName = gridNestedViewItemObj.OwnerTableView.DataKeyValues[parentItemObj.ItemIndex]["BillingName"].ToString();
14.   
15. 
16.                    Panel BillingInfo = (Panel)((GridDataItem)e.Item).ChildItem.FindControl("pnlBillingInfo");
17.                    Label BillingSame = (Label)((GridDataItem)e.Item).ChildItem.FindControl("lblBillingSame");
18.                  
19. 
20.                    if (!String.IsNullOrEmpty(BillingName))
21.                    {
22.                        BillingInfo.Visible = true;
23.                        BillingSame.Visible = false;
24.                    }
25.                    else
26.                    {
27.                        BillingInfo.Visible = false;
28.                        BillingSame.Visible = true;
29.                    }
30.}
31.}
32.}

2 Answers, 1 is accepted

Sort by
0
Jessica B.
Top achievements
Rank 1
answered on 11 Jun 2015, 06:09 PM

I've tried putting the values I need in the parent table, but that still doesn't help. I've tried everything I've found online but nothing is working!

 All I want to do is load my dataset into the GridNestedView from my datasource (that part is working fine), and before it displays, manipulate some of the controls based on values from the datasource.

Pulling my hair out!

0
Konstantin Dikov
Telerik team
answered on 15 Jun 2015, 02:29 PM
Hello Jessica,

If you need to get reference to a specific control in the GirdNestedView and manipulate those controls depending on a specific value in the parent item, you could to do this within the OnPreRender event of the grid:
protected void RadGrid1_PreRender(object sender, EventArgs e)
{
    foreach (GridDataItem item in RadGrid1.Items)
    {
        if (item.Expanded)
        {
            GridNestedViewItem nestedView = item.ChildItem as GridNestedViewItem;
            string someValue = item.GetDataKeyValue("CustomerID").ToString();
            (nestedView.FindControl("Label1") as Label).Text = someValue + " " + DateTime.Now.ToString();  
        }
    }
}

For detailed information about accessing controls in RadGrid you can refer to the following help article:
Hope this helps.


Regards,
Konstantin Dikov
Telerik
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 Feedback Portal and vote to affect the priority of the items
Tags
Grid
Asked by
Jessica B.
Top achievements
Rank 1
Answers by
Jessica B.
Top achievements
Rank 1
Konstantin Dikov
Telerik team
Share this question
or