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

Hierarchical RadGrid row color

4 Answers 132 Views
Grid
This is a migrated thread and some comments may be shown as answers.
dev79
Top achievements
Rank 1
dev79 asked on 24 Mar 2009, 05:27 PM
I have a 3 level Hierarchical RadGrid.  I want to be able to color the row of the 1st level if a value on the 3rd level (column1== complete) is complete then color the row green.  I followed this demo right here: http://demos.telerik.com/aspnet-ajax/grid/examples/hierarchy/declarativerelations/defaultcs.aspx.

thanks!

4 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 25 Mar 2009, 05:59 AM
Hi,

Try setting the HierarchyLoadMode property of the 1st and 2nd level Grid to Client and try the following code snippet in the PreRender event to achieve the desired scenario.

ASPX:

<
MasterTableView  HierarchyLoadMode="Client"   DataSourceID="SqlDataSource1"
 ......... 
    <DetailTables> 
           <telerik:GridTableView runat="server" HierarchyLoadMode="Client"    DataSourceID="SqlDataSource2" > 
                 ......... 

CS:
 
protected void RadGrid1_PreRender(object sender, EventArgs e) 
    { 
 
        GridTableView nestedTableView1 = (RadGrid1.MasterTableView.Items[0] as GridDataItem).ChildItem.NestedTableViews[0]; 
        if (nestedTableView1 != null
        { 
            GridTableView nestedTableView2 = (nestedTableView1.Items[0] as GridDataItem).ChildItem.NestedTableViews[0]; 
            if (nestedTableView2 != null
            { 
                foreach (GridDataItem item in nestedTableView2.Items) 
                { 
                    if (item["column1"].Text.Trim() == "complete"
                    { 
                        RadGrid1.MasterTableView.Items[0].BackColor = System.Drawing.Color.Red; 
                         
                    } 
                } 
            } 
        } 
        
        
    } 

Regards
Shinu.

0
dev79
Top achievements
Rank 1
answered on 25 Mar 2009, 01:49 PM
Hello, i tried what you suggested, however it did not work for me.  The row is still not colored. 
0
Shinu
Top achievements
Rank 2
answered on 26 Mar 2009, 04:08 AM
Hi,

The above given code is working fine on my end. Have you set the HierarchyLoadMode to Client? It would be nice if you could send your aspx and code behind.

Thanks
Shinu.
0
dev79
Top achievements
Rank 1
answered on 26 Mar 2009, 05:33 PM

Shinu - yes, I have set  HierarchyLoadMode to Client for the 1st & 2nd level grid, but did not work. 

Below is a different approach i took.  Do you think you can help me implement the row color I asked about from my original message on the following code? 

Thanks in advance!

.aspx code

 

    <form runat="server" id="mainForm" method="post" style="width: 100%;">  
        <strong>BTR Website Project List<br /></strong><br /> 
        <asp:scriptmanager runat="server" id="ScriptManager1"></asp:scriptmanager> 
          
        <div> 
            <asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder> 
            <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server"></telerik:RadAjaxManager>   
        </div> 
 
        <asp:SqlDataSource ID="SqlDataSource1_proj" ConnectionString="<%$ ConnectionStrings:ConnectionString3 %>" SelectCommand="SELECT * FROM PROJECTS order by project_id" runat="server"></asp:SqlDataSource> 
        <asp:SqlDataSource ID="SqlDataSource1_issues" ConnectionString="<%$ ConnectionStrings:ConnectionString3 %>" ProviderName="System.Data.SqlClient" SelectCommand="SELECT * from ISSUES where project_id=@PROJECT_ID" runat="server">  
            <SelectParameters> 
                <asp:SessionParameter Name="PROJECT_ID" SessionField="PROJECT_ID" Type="Int32"/>  
            </SelectParameters> 
        </asp:SqlDataSource> 
        <asp:SqlDataSource ID="SqlDataSource1_milestones" ConnectionString="<%$ ConnectionStrings:ConnectionString3 %>" ProviderName="System.Data.SqlClient" SelectCommand="SELECT * from MILESTONES where issue_id=@ISSUE_ID and active='Y'" runat="server">  
            <SelectParameters> 
                <asp:SessionParameter Name="ISSUE_ID" SessionField="ISSUE_ID" Type="Int32" /> 
            </SelectParameters> 
        </asp:SqlDataSource>      
    </form> 

 

.cs code

public partial class Default_Tracker : System.Web.UI.Page  
{  
    private void DefineGridStructure()  
    {  
        RadGrid RadGrid1 = new RadGrid();  
 
        RadGrid1.ID = "RadGrid1";  
        RadGrid1.DataSourceID = "SqlDataSource1_proj";  
 
        RadGrid1.MasterTableView.DataKeyNames = new string[] { "PROJECT_ID" };  
 
        RadGrid1.Width = Unit.Percentage(98);  
        RadGrid1.PageSize = 20;  
        RadGrid1.AllowPaging = true;  
        RadGrid1.AllowSorting = true;  
        RadGrid1.PagerStyle.Mode = GridPagerMode.NextPrevAndNumeric;  
        RadGrid1.AutoGenerateColumns = false;  
        RadGrid1.ShowStatusBar = true;  
 
        RadGrid1.MasterTableView.PageSize = 20;  
 
 
        RadGrid1.ItemDataBound += new GridItemEventHandler(RadGrid1_ItemDataBound);  
        //Add columns  
        GridBoundColumn boundColumn;  
        boundColumn = new GridBoundColumn();  
        boundColumn.DataField = "PROJECT_ID";  
        boundColumn.HeaderText = "ID";  
        RadGrid1.MasterTableView.Columns.Add(boundColumn);  
 
        boundColumn = new GridBoundColumn();  
        boundColumn.DataField = "PROJECT_TITLE";  
        boundColumn.HeaderText = "Project Title";  
        RadGrid1.MasterTableView.Columns.Add(boundColumn);  
 
        boundColumn = new GridBoundColumn();  
        boundColumn.DataField = "PROJECT_DESCRIPTION";  
        boundColumn.HeaderText = "Description";  
        RadGrid1.MasterTableView.Columns.Add(boundColumn);  
 
 
        //Detail table - Issues (II in hierarchy level)  
        GridTableView tableViewOrders = new GridTableView(RadGrid1);  
        tableViewOrders.DataSourceID = "SqlDataSource1_issues";  
        tableViewOrders.Width = Unit.Percentage(100);  
 
        tableViewOrders.DataKeyNames = new string[] { "ISSUE_ID" };  
 
        GridRelationFields relationFields = new GridRelationFields();  
        relationFields.MasterKeyField = "PROJECT_ID";  
        relationFields.DetailKeyField = "PROJECT_ID";  
        tableViewOrders.ParentTableRelation.Add(relationFields);  
 
        RadGrid1.MasterTableView.DetailTables.Add(tableViewOrders);  
 
 
 
        //Add columns  
        boundColumn = new GridBoundColumn();  
        boundColumn.DataField = "ISSUE_ID";  
        boundColumn.HeaderText = "ISSUE_ID";  
        tableViewOrders.Columns.Add(boundColumn);  
 
        boundColumn = new GridBoundColumn();  
        boundColumn.DataField = "ISSUE_TITLE";  
        boundColumn.HeaderText = "ISSUE_TITLE";  
        tableViewOrders.Columns.Add(boundColumn);  
 
        boundColumn = new GridBoundColumn();  
        boundColumn.DataField = "ISSUE_DESCRIPTION";  
        boundColumn.HeaderText = "ISSUE_DESCRIPTION";  
        tableViewOrders.Columns.Add(boundColumn);  
 
        //Detail table Issue-Milestones(III in hierarchy level)  
        GridTableView tableViewOrderDetails = new GridTableView(RadGrid1);  
        tableViewOrderDetails.DataSourceID = "SqlDataSource1_milestones";  
        tableViewOrderDetails.Width = Unit.Percentage(100);  
 
        tableViewOrders.DataKeyNames = new string[] { "ISSUE_ID" };  
 
        GridRelationFields relationFields2 = new GridRelationFields();  
        relationFields2.MasterKeyField = "ISSUE_ID";  
        relationFields2.DetailKeyField = "ISSUE_ID";  
        tableViewOrderDetails.ParentTableRelation.Add(relationFields2);  
 
        tableViewOrders.DetailTables.Add(tableViewOrderDetails);  
 
        boundColumn = new GridBoundColumn();  
        boundColumn.DataField = "MILESTONE_ID";  
        boundColumn.HeaderText = "MILESTONE_ID";  
        tableViewOrderDetails.Columns.Add(boundColumn);  
 
        boundColumn = new GridBoundColumn();  
        boundColumn.DataField = "MILESTONE_STATUS";  
        boundColumn.HeaderText = "MILESTONE_STATUS";  
        tableViewOrderDetails.Columns.Add(boundColumn);  
 
        boundColumn = new GridBoundColumn();  
        boundColumn.DataField = "MILESTONE_PERCENTAGE";  
        boundColumn.HeaderText = "MILESTONE_PERCENTAGE";  
        tableViewOrderDetails.Columns.Add(boundColumn);  
 
        boundColumn = new GridBoundColumn();  
        boundColumn.DataField = "MILESTONE_START_DATE";  
        boundColumn.HeaderText = "MILESTONE_START_DATE";  
        tableViewOrderDetails.Columns.Add(boundColumn);  
 
        boundColumn = new GridBoundColumn();  
        boundColumn.DataField = "MILESTONE_END_DATE";  
        boundColumn.HeaderText = "MILESTONE_END_DATE";  
        tableViewOrderDetails.Columns.Add(boundColumn);  
 
        boundColumn = new GridBoundColumn();  
        boundColumn.DataField = "MILESTONE_NOTES";  
        boundColumn.HeaderText = "MILESTONE_NOTES";  
        tableViewOrderDetails.Columns.Add(boundColumn);  
 
        //Add the RadGrid instance to the controls  
        this.PlaceHolder1.Controls.Add(RadGrid1);  
    }  
 
 
    protected void Page_Init(object source, System.EventArgs e)  
    {  
        DefineGridStructure();  
    }  
 
    protected void Page_Load(object sender, EventArgs e)  
    {  
        RadGrid Grid1 = (RadGrid)PlaceHolder1.FindControl("RadGrid1");  
        RadAjaxManager1.AjaxSettings.AddAjaxSetting(Grid1, Grid1);  
 
        if (!IsPostBack)  
        {  
 
            //Setting Selected index prior to binding RadGrid:  
            //If the index is in detail table, parent items will be expanded  
            //automatically   
            Grid1.SelectedIndexes.Add(1, 0, 1, 0, 0);  
            //Index of 1, 0, 1, 0, 0 means:  
            //1 - item with index 1 in the MasterTabelView  
            //0 - detail table with index 0  
            //1 - item with index 1 (the second item) in the first detail table  
            //0 - 0 the third-level detail table  
            //0 - the item with index 0 in the third-level table  
        }  
    }  

 

 

Tags
Grid
Asked by
dev79
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
dev79
Top achievements
Rank 1
Share this question
or