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

How can I add custom columns in a detail table based on the parent row?

3 Answers 98 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Sean
Top achievements
Rank 2
Sean asked on 18 Jan 2012, 08:20 PM
Hi All,

   So I have a grid that I define programmatically and then add to the page via a PlaceHolder control. I set up the data for the view in "DefineGridStructure" stolen liberally from the Telerik example so I have the base structure for the MasterTableView and the detail TableViews which works well. Where I run into trouble is that during the DetailTableDataBind. Depending on the parent row I may add some row specific columns to the detail table that may only exist for that parent row. Basically the grid has groups of people with the Top level having a group comparison so all the columns are the same, The 2nd level has the people which are all part of the group from the parent row, but now may have some columns that are specific to that group. So what I end up with is something like this:

·         Group Name 1       | Column A | Column B | Column C

    • Person 1 | Column A | Column B | Column C | Column D
    • Person 2          | Column A | Column B | Column C | Column D

·         Group Name 2        | Column A | Column B | Column C 

    • Person 3          | Column A | Column B | Column C | Column E | Column D
    • Person 4          | Column A | Column B | Column C | Column E | Column D

 Right now it works great on the initial load but during any postback/callback it removes all the custom columns, which makes sense since I don't define them in the "DefineGrideStructure". With all that said is there a way to override the columns of a detail table for a specific parent row in say like the prerender or a similar event? And is there an example online for this?

Thanks in advance for any pointers

Sean

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 19 Jan 2012, 05:52 AM
Hello Sean,

You can access the DataKeyValue in DetailTableBind event and populate the detailtable accordingly. Check the following demo which explains more about this.
Grid / Programmatic Binding

-Shinu.
0
Sean
Top achievements
Rank 2
answered on 19 Jan 2012, 05:28 PM
Hi Shinu,

     Thanks for the quick response. I am actually using the DataKeyValue in the DetailTableBind as follows: 

GridDataItem dataItem = e.DetailTableView.ParentItem;
if (e.DetailTableView.Name == "UserLevel")
{
    GridTableView userView = e.DetailTableView;
    int sgID = Convert.ToInt32(dataItem.GetDataKeyValue("SuperGroupID.Value"));
    BindUserLevelColumnsForSuperGroup(ref userView, sgID);
    userView.DataSource = DataService.GetDataForUserSGLevel(sgID, this.SelectionCriteria, this.DashboardConfig, _languageID);
}

 the issue I am having is with the "BIndUserLevelColumnsForSuperGroup" which creates columns specific to a particular parent row. The custom columns appear on the initial load but not on any postbacks. The postbacks only contain the columns I have defined in the Page_Init event (aka the DefineGridStrucure method) and this makes sense to me as the DetailTableBind event does not need to be fired again on a post back.  I am struggling on how to recreate these group specific columns during the subsequent postbacks so that they are displayed, so any help on how I can re-create the custom columns on postback would be helpful or if there is an alternative I could use.

Cheers

Sean
0
Sean
Top achievements
Rank 2
answered on 25 Jan 2012, 03:54 PM
Hi All,

    For anyone that wants to do the same thing. The issue was that in callbacks/postbacks I was not defining the columns again. I could never figure out where else I could do the Row-based defining of the detail tables, so what I did was define ALL the possible columns then in the needs datasource and DetailTableBind  events I would hide all the columns that are not part of that particular row. You can define them once then the viewstate will recover those settings on postback. Thanks to another forum poster who made the comment that the hidden columns don't get rendered (which just makes sense) meaning that it is not as much of a performance impact as I thought it would.

Cheers

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