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

Hierarchy Grid detail table DataSource

5 Answers 109 Views
Grid
This is a migrated thread and some comments may be shown as answers.
RJ
Top achievements
Rank 1
RJ asked on 20 Jan 2011, 01:50 AM
I have a list of objects that are used as a datasource for the detail table. Not all the fields from the datasource are in the detail grid. I am using the edit form template. Is there any way I can access the detail table datasource fields (not in the detail grid) in the updatecommand event.

Thanks

5 Answers, 1 is accepted

Sort by
0
Marin
Telerik team
answered on 20 Jan 2011, 03:23 PM
Hi RJ,

If you need to get the values for the edit form you can use the ExtractValuesFromItem method of the OwnerTableView. You can find further information in this help article in the section Example1: Using ExtractValuesFromItem.

All the best,
Marin
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
RJ
Top achievements
Rank 1
answered on 20 Jan 2011, 04:04 PM
Hi Marin,

The ExtractValuesFromItem method provides information if the fields are  bound to the grid. However,the list DataSource has additional fields that are not part of the grid. How can I get the additional fields from the DataSource which are not part of the grid.

Thank you
0
Marin
Telerik team
answered on 21 Jan 2011, 10:42 AM
Hi RJ,

You can access the actual object to which the grid item is bound by using the DataItem property which will return your custom data object and then you can access its fields. Note that in order the DataItem property to be initilized you need to Rebind the grid first. Here is a sample code snippet:

protected void RadGrid1_UpdateCommand(object sender, GridCommandEventArgs e)
    {
        RadGrid1.Rebind();
        CustomObject obj = e.Item.OwnerTableView.Items[e.Item.ItemIndex].DataItem as CustomObject;
        //you can access obj.Field1, obj.Field2, etc.
    }

Additionally you can get access to the whole collection using the DataSource property of the grid, assuming it has been set in the NeedDataSource event in order to bind the grid.

List<CustomObject> customCollection = RadGrid1.DataSource as List<CustomObject>;
        // access properties of collection


Hope this helps.

 

All the best,
Marin
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
RJ
Top achievements
Rank 1
answered on 21 Jan 2011, 04:06 PM

Hi Marin,

I need the datasource for the detail table and it is set in the detail table data bind event. How can I get access to the DataSource property of the detail table in the update command event.

Thank you.
0
Marin
Telerik team
answered on 24 Jan 2011, 09:39 AM
Hi RJ,

 You can get access to the DataSource property of the detail table in the following way:

protected void RadGrid1_UpdateCommand(object sender, GridCommandEventArgs e)
        {
            //you need this check in case you have more that one levels of hierarchy and you have set the Name of the DetailTable so that they can be distinguished
            if (e.Item.OwnerTableView.Name == "Orders")
            {
                e.Item.OwnerTableView.Rebind();
                DataSet ds = e.Item.OwnerTableView.DataSource as DataSet;
                
             }
                 
            }
        }

 

All the best,
Marin
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
Tags
Grid
Asked by
RJ
Top achievements
Rank 1
Answers by
Marin
Telerik team
RJ
Top achievements
Rank 1
Share this question
or