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

Grid Self Referencing Hierarchy Issue

3 Answers 37 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Abdurrahman Battal
Top achievements
Rank 1
Abdurrahman Battal asked on 05 May 2009, 03:20 PM
Hi,

I am trying to use the grid with self referencing; however I am unable to solve some issues. The first and most important problem is, if I choose "AutoGenerateColumns" as true; it all works fine. However; I need to specify the columns during runtime on serverside; by adding columns to the grid. When "AutoGenerateColumns" is set to false and columns are added on the server side, grid does not display the hierarchy at all; but just lists the items.

Please let me know what to do to be able to add columns at serverside during page's load or init events; so that the self referencing hierarchy works.

I am exhausted of trying to solve this issue and tried everything I can; so any help is greatly appreciated.

Thanks.

3 Answers, 1 is accepted

Sort by
0
Serrin
Top achievements
Rank 1
answered on 05 May 2009, 08:14 PM
Hey Abdurrahman,

I think the problem that you're going to run into with this is that you would need to know the exact setup of the grid beforehand.  In looking into the code from the self-referencing hierarchy demo, there are both GridBoundColumns and GridExpandColumns at work here, so theoretically you would need to have knowledge of how to structure your grid before you could put any data into it to make the hierarchy.

Out of curiosity, why do you need to create the columns during runtime if the basic self-referencing hierarchy example takes care of creating everything for you?  Knowing this might help some of the Grid-wizards that frequent here to come up some some sort of workaround or trick that could fit your scenario.
0
Marc Plaxton-Harrison
Top achievements
Rank 1
answered on 07 May 2010, 08:28 AM
Hi Serrin,

I have run into exactly the same problem as Abdurrahman.
I don't know what his reasoning for it would be, however my purpose is this.

I have a self-referencing table with fields - ID, Name, Date, ParentID.
Unfortunately the system i'm developing requires me to only display the Name and Date fields and hide the ID's.
the only way to accomplish that is to hide the respective columns at run-time in code, which doesn't seem to be working as Abdurrahman stated above.

I have yet to find resolution to this problem and help would be greatly appreciated.

Regards
0
Veli
Telerik team
answered on 12 May 2010, 11:30 AM
Hi guys,

@Mark
You can still have auto-generated columns in RadGrid. Of all you need is to hide one of them, you can use the ColumnCreated event of the grid. ColumnCreated is fired for auto-generated columns only, so you can check the column name and hide the ID column:

public void RadGrid1_ColumnCreated(object sender, Telerik.Web.UI.GridColumnCreatedEventArgs e)
{
    if (e.Column.UniqueName == "ID")
    {
        e.Column.Visible = false;
    }
}


@Abdurrahman
If your columns do not change on postback, i.e. you always create the same set of columns, then the standard rules for programmatic grid creation apply for your case. If your columns may change on postback, then you need to create RadGrid entirely in the code-behind (in Page_Init) and add it to a container on the page (refer to section "Creating the grid entirely in the code-behind" in the linked article).

Kind regards,
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.
Tags
Grid
Asked by
Abdurrahman Battal
Top achievements
Rank 1
Answers by
Serrin
Top achievements
Rank 1
Marc Plaxton-Harrison
Top achievements
Rank 1
Veli
Telerik team
Share this question
or