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

How to Bind different structured tables to GridTableView

2 Answers 109 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Tray
Top achievements
Rank 1
Tray asked on 20 Dec 2012, 01:51 PM
Hi,

i want to develop a hierarchy grid with pragmatically Binding using DetailTableDataBind Event in this i have different tables and based on id i may get different structured tables with different columns how can i bind these tables to  GridTableView  in Telerik please help in this aspect 


am using this code for  DetailTableDataBind Event
protected void Rgrid_DetailTableDataBind(object source, Telerik.Web.UI.GridDetailTableDataBindEventArgs e)
        {
            GridDataItem dataItem = (GridDataItem)e.DetailTableView.ParentItem;
            int PNameID = Convert.ToInt16(dataItem.GetDataKeyValue("PNameID"));
             
                try
                {
                    Common ObjCommon = new Common();
 
                    DataSet ds = ObjCommon.DocumentsWithFields(PNameID);
                       
                          
                  
                    if (ds.Tables.Count > 0)
                    {
                        if (ds.Tables[0].Rows.Count > 0)
                        {
                            
 
                            e.DetailTableView.Columns.Clear();
                           e.DetailTableView.DataSource= ds.Tables[0];
                            
                           
                        }
                    }
                    else
                    {
                        var PropertyDocs = (ObjCommon .DocumentsWithoutFields(PNameID)).ToList();
                        e.DetailTableView.DataSource = PropertyDocs;
                        
                    }
                    
                }
               
                catch (Exception ex)
                {
            Response.Write(ex.Message);
                }
             
        }

above code return correct table structure but not binding to Gridtable view

2 Answers, 1 is accepted

Sort by
0
Elliott
Top achievements
Rank 2
answered on 20 Dec 2012, 04:51 PM
would it be better to hide and show columns depending on the type of table?
the Telerik grid doesn't crash if the data source is missing a column or two
0
Eyup
Telerik team
answered on 24 Dec 2012, 01:53 PM
Hello Sreebabu,

The following topic describes how to use the DetailTableBind event:
http://www.telerik.com/help/aspnet-ajax/grid-hierarchical-data-binding-using-detailtabledatabind.html

You can also check out this demo for a practical implementation:
http://demos.telerik.com/aspnet-ajax/grid/examples/programming/detailtabledatabind/defaultcs.aspx

I hope this will prove helpful.

All the best,
Eyup
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Grid
Asked by
Tray
Top achievements
Rank 1
Answers by
Elliott
Top achievements
Rank 2
Eyup
Telerik team
Share this question
or