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

Hierarchical Radgrid Detail table manipulation

3 Answers 151 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Shivan
Top achievements
Rank 1
Shivan asked on 23 Oct 2010, 07:59 AM
Dear Telerik Team,

I have a requirement [ Hierarchical grid ] where the detail table [ Leaf ] content will change according to the row value. ie, if the row field value is "contract", the detail table should take value from contract table, and if the row field value is "phase", the detail table should take value from phase table etc.

Below I give the code sample I have done,

protected

 

void RadGrid1_DetailTableDataBind(object source, GridDetailTableDataBindEventArgs e)

 

{

 

    int

 

wbsLevelID = Convert.ToInt32(dataItem.GetDataKeyValue("wbsLevelID").ToString());

    string

 

wbsLevelCode = dataItem.GetDataKeyValue("wbsLevelCode").ToString();

 

    if

 

(wbsLevelCode == "Category" && wbsLevelID!=0)

 

    {

 

      

 

 

 

        DataTable

 

 

dtSource = (DataTable)e.DetailTableView.DataSource;

 

        e.DetailTableView.DataSource = GetContractRowDataTable(dtSource, wbsLevelID);
    }
}

 

public

 

 

DataTable GetContractRowDataTable(DataTable dtSource, int categoryID,int wbsLevelID)

 

{

 

    ///////// I want to define columns and add rows from here.
   

 

}

//////////////////////////////

Will this logic work?

Please help me in this scenario.
Thanks

 

 

 

 

 

3 Answers, 1 is accepted

Sort by
0
Accepted
Veli
Telerik team
answered on 27 Oct 2010, 12:07 PM
Hello Shiva,

Yes, believe you can take a similar approach for databinding your detail tables to different data sources:

protected void RadGrid1_DetailTableDataBind(object sender, GridDetailTableDataBindEventArgs e)
{
    string levelCode = (string)e.DetailTableView.ParentItem.GetDataKeyValue("wbsLevelCode");
    switch (levelCode)
    {
        case "Contract":
            e.DetailTableView.DataSource = [Contract data];
            break;
 
        case "Phase":
            e.DetailTableView.DataSource = [Phase data];
            break;
    }
}

In the above sample code the field wbsLevelCode is added to the MastertableView.DataKeyNames collection and we retrieve the value for each master table item when its detail table binds.

Veli
the Telerik team
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 Public Issue Tracking system and vote to affect the priority of the items
0
Shivan
Top achievements
Rank 1
answered on 06 Nov 2010, 01:24 PM
Hello,

I have one more doubt.
Can we mamipulate the current row itself, not the detail table?

not like,
e.DetailTableView.DataSource = [Phase data];

but like
e.CurrentRow.Data ="Some thing";

Thanks
0
Princy
Top achievements
Rank 2
answered on 08 Nov 2010, 07:13 AM
Hello Shiva,

You can manipulate the data item in detailtable by accessing the GridDataItem of DetailTable in ItemDataBound event like below.

ASPX:
<DetailTables>
      <telerik:GridTableView Name="DetailTable" runat="server" >
           . . . . . . . . . . . .

C#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
  {
     if (e.Item is GridDataItem && e.Item.OwnerTableView.Name == "DetailTable") // check with name of DetailTable
      {
          GridDataItem item = (GridDataItem)e.Item; // accessing GridDataItem in DetailTable
          item["ColumnUniqueName"].Text = "new text"; // changing cell value
      }
  }

Thanks,
Princy.
Tags
Grid
Asked by
Shivan
Top achievements
Rank 1
Answers by
Veli
Telerik team
Shivan
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Share this question
or