RadGrid with nested grids

2 posts, 0 answers
  1. Rey
    Rey avatar
    2 posts
    Member since:
    Jul 2015

    Posted 01 Jul 2015 Link to this post

    I have a RadGrid. Trying to change the font colors when an specific value is present. As an example...If Status Code != 0 then change color to red. Now I have that working fine, however when I click on any of the nested grids I get an error stating that "Status Code" isn't in the grid. I know that because It is a different grid (under the parent) for some reason it is still validating against the parent when it shouldn't. Any ideas? It works at the parent level. I don't want the sub grids to change at all, just the parent.

     

    Here is the ASP code:

    <telerik:RadGrid
        runat="server"
        ID="RadGrid1"
        AllowPaging="true" 
        AllowFilteringByColumn="true" 
        AllowSorting="true"    
        PageSize="40" 
        AutoGenerateColumns="True" 
        CellSpacing="-1" 
        GridLines="Both" 
        GroupPanelPosition="Top" 
        DataSourceID="SqlDataSource1" OnItemDataBound="grd_RowDataBound">
        <MasterTableView 
            EnableHeaderContextMenu="true" 
            OnPreRender="Grid1_PreRender"
            DataKeyNames="trxids,TransactionType" 
            Name="Master" AutoGenerateColumns="true" runat="server">
                    <DetailTables>
                        <telerik:GridTableView HeaderStyle-Font-Bold="true" AlternatingItemStyle-BackColor="LightBlue"
                            DataSourceID="SqlDataSource2"
                            AllowFilteringByColumn="false" 
                            AllowSorting="false"
                            DataKeyNames="trxid,TransactionType" >
                              <ParentTableRelation>
                                  <telerik:GridRelationFields DetailKeyField="trxids" MasterKeyField="trxids"></telerik:GridRelationFields>  
                                  <telerik:GridRelationFields DetailKeyField="TransactionType" MasterKeyField="TransactionType"></telerik:GridRelationFields>
                              </ParentTableRelation>

                                 <DetailTables>
                                     <telerik:GridTableView HeaderStyle-Font-Bold="true" ItemStyle-ForeColor="DarkRed"
                                        DataSourceID="SqlDataSource3" 
                                        AllowFilteringByColumn="false"
                                        AllowSorting="false"  >
                                          <ParentTableRelation>
                                              <telerik:GridRelationFields DetailKeyField="trxid" MasterKeyField="trxid"></telerik:GridRelationFields>  
                                              <telerik:GridRelationFields DetailKeyField="TransactionType" MasterKeyField="TransactionType"></telerik:GridRelationFields>
                                          </ParentTableRelation>
                                     </telerik:GridTableView>
                                 </DetailTables>
                        </telerik:GridTableView>
                    </DetailTables>
                </MasterTableView>
    </telerik:RadGrid>

     

     

    Code behind is as follows:

        protected void grd_RowDataBound(object sender, GridItemEventArgs e)
        {
            if (e.Item is GridDataItem)
            {

                GridDataItem item = (GridDataItem)e.Item;

                TableCell cell = (TableCell)item["Status Code"];
                if (cell.Text != "0")
                {
                    cell.ForeColor = System.Drawing.Color.Red;
                    cell.Font.Bold = true;
                    cell.Font.Size = 8;
                    cell.BackColor = System.Drawing.Color.LightGray;


                    GridDataItem item1 = (GridDataItem)e.Item;
                    TableCell cell1 = (TableCell)item["count"];
                    cell1.ForeColor = System.Drawing.Color.Red;
                    cell1.Font.Bold = true;
                    cell1.Font.Size = 8;
                    cell1.BackColor = System.Drawing.Color.LightGray;


                }
    }
         } 

     

  2. Eyup
    Admin
    Eyup avatar
    3795 posts

    Posted 06 Jul 2015 Link to this post

    Hello Rey,

    You can resolve this issue by using the following property:
    <MasterTableView ... Name="MasterTableName">
    C#:
    protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
    {
        if (e.Item.OwnerTableView.Name == "MasterTableName")
        {
            // execute custom logic
        }
    }

    Hope this helps. Please give it a try and let me know if it works for you.

    Regards,
    Eyup
    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
Back to Top