GridNestedViewItem values

3 posts, 0 answers
  1. Jessica B.
    Jessica B. avatar
    7 posts
    Member since:
    May 2010

    Posted 10 Jun 2015 Link to this post

    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"  
                    <asp:Parameter Name="ID" Type="Int32" />

    <NestedViewSettings DataSourceID="dsViewCredit">
    <telerik:GridRelationFields DetailKeyField="ID" MasterKeyField="ID" />
    01.protected void Grid_ItemCreated(object source, GridItemEventArgs e)
    02.        {
    03.            if (e.Item is GridNestedViewItem)
    04.            {
    06.                GridNestedViewItem gridNestedViewItemObj = e.Item as GridNestedViewItem;
    07.                GridDataItem parentItemObj = (e.Item as GridNestedViewItem).ParentItem;
    08.                if (gridNestedViewItemObj == null || parentItemObj == null)
    09.                    return;
    11.                if (gridNestedViewItemObj.OwnerTableView.DataKeyValues != null)
    12.                {
    13.                    string BillingName = gridNestedViewItemObj.OwnerTableView.DataKeyValues[parentItemObj.ItemIndex]["BillingName"].ToString();
    16.                    Panel BillingInfo = (Panel)((GridDataItem)e.Item).ChildItem.FindControl("pnlBillingInfo");
    17.                    Label BillingSame = (Label)((GridDataItem)e.Item).ChildItem.FindControl("lblBillingSame");
    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.                    }

  2. Jessica B.
    Jessica B. avatar
    7 posts
    Member since:
    May 2010

    Posted 11 Jun 2015 Link to this post

    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!

  3. Konstantin Dikov
    Konstantin Dikov avatar
    2466 posts

    Posted 15 Jun 2015 Link to this post

    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.

    Konstantin Dikov
    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
Back to Top