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

Binding NestedViewSettings DataSource from CodeBehind

1 Answer 80 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Benjamin
Top achievements
Rank 1
Benjamin asked on 17 Jan 2013, 07:56 AM
Hi, I am currently doing a mock-up project and therefore, have no establish a database for it.  I am using this to currently bind data onto the RadGrid.

protected void LoadDataToGrid()
        {
            DataTable dt = new DataTable();
            //Set the datafield name
            DataColumn cl = new DataColumn("status");
            dt.Columns.Add(cl);
            cl = new DataColumn("Item_Code");
            dt.Columns.Add(cl);
            cl = new DataColumn("Item_Desc");
            dt.Columns.Add(cl);
            cl = new DataColumn("Vendor_Name");
            dt.Columns.Add(cl);
            cl = new DataColumn("Uom");
            dt.Columns.Add(cl);
            cl = new DataColumn("Moq");
            dt.Columns.Add(cl);
            cl = new DataColumn("Qty");
            dt.Columns.Add(cl);
            cl = new DataColumn("Cur");
            dt.Columns.Add(cl);
            cl = new DataColumn("Price");
            dt.Columns.Add(cl);
            cl = new DataColumn("Total");
            dt.Columns.Add(cl);
            cl = new DataColumn("Type");
            dt.Columns.Add(cl);
 
             
            //Set the static data for row 1
            DataRow dr = dt.NewRow();
            dr[0] = "";
            dr[1] = "07-11-017"
            dr[2] = "PAPER PUNCHER (3 HOLES)";
            dr[3] = "Internal";
            dr[4] = "PC";
            dr[5] = "1";
            dr[6] = "1";
            dr[7] = "SGD";
            dr[8] = "130.00";
            dr[9] = "130.00";
            dr[10] = "NS";
            dt.Rows.Add(dr);
 
 
            //Set the static data for row 2
            dr = dt.NewRow();
            dr[0] = "";
            dr[1] = "07-09-069";
            dr[2] = "BINDING STRIPS A4 (MULTI-COLOUR) (LOT OF 100/50PC) ";
            dr[3] = "Internal";
            dr[4] = "PC";
            dr[5] = "1";
            dr[6] = "1";
            dr[7] = "SGD";
            dr[8] = "60.00";
            dr[9] = "60.00";
            dr[10] = "NS";
            dt.Rows.Add(dr);
 
            //Set the static data for row 3
            dr = dt.NewRow();
            dr[0] = "";
            dr[1] = "01-38-002";
            dr[2] = "LAMINATING MACHINE A4, LMA400";
            dr[3] = "Internal";
            dr[4] = "PC";
            dr[5] = "1";
            dr[6] = "1";
            dr[7] = "SGD";
            dr[8] = "160.00";
            dr[9] = "160.00";
            dr[10] = "NS";
            dt.Rows.Add(dr);
 
            //Set the static data for row 4
            dr = dt.NewRow();
            dr[0] = "";
            dr[1] = "99-09-901";
            dr[2] = "BOLTED CONNECTOR";
            dr[3] = "Internal";
            dr[4] = "PC";
            dr[5] = "10";
            dr[6] = "10";
            dr[7] = "SGD";
            dr[8] = "1.50";
            dr[9] = "15.00";
            dr[10] = "ST";
            dt.Rows.Add(dr);
 
            //Set the static data for row 5
            dr = dt.NewRow();
            dr[0] = "";
            dr[1] = "99-07-905";
            dr[2] = "GUY STRAIN INSULATOR";
            dr[3] = "Internal";
            dr[4] = "PC";
            dr[5] = "100";
            dr[6] = "100";
            dr[7] = "SGD";
            dr[8] = "1.00";
            dr[9] = "100.00";
            dr[10] = "ST";
            dt.Rows.Add(dr);
 
            //Set the static data for row 6
            dr = dt.NewRow();
            dr[0] = "";
            dr[1] = "99-01-505";
            dr[2] = "HOT LINE CLAMP";
            dr[3] = "Internal";
            dr[4] = "PC";
            dr[5] = "500";
            dr[6] = "500";
            dr[7] = "SGD";
            dr[8] = "2.00";
            dr[9] = "1000.00";
            dr[10] = "ST";
            dt.Rows.Add(dr);
 
            RadGrid1.DataSource = dt;
            RadGrid1.DataBind();
            Session.Add("dtCart",  dt);
        }

However, I couldn't find any way to use the same way to bind this datasource for the <NestedViewSettings> DataSourceID.

1 Answer, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 22 Jan 2013, 07:05 AM
Hi Benjamin,

Please note that performing complex grid operations such as Inserting, Deleting, Updating, Hierarchy relations, Grouping, Paging, Sorting, Filtering require accommodating appropriate database operations. To use them with Simple Databinding you will need to declare custom event handling for every operation which requires binding to your DataSource. Therefore, we strongly recommend the use of more advanced databinding methods, which automatically handle the aforementioned functions:
Declarative DataSource
Advanced Data Binding

In addition, you can check out the following demos for a practical implementation of hierarchical grid structure:
- Standard Hierarchy
http://demos.telerik.com/aspnet-ajax/grid/examples/hierarchy/declarativerelations/defaultcs.aspx
  - Programmatic Hierarchy
http://demos.telerik.com/aspnet-ajax/grid/examples/hierarchy/autogeneratedhierarchy/defaultcs.aspx
  - Hierarchy with Templates
http://demos.telerik.com/aspnet-ajax/grid/examples/hierarchy/nestedviewtemplate/defaultcs.aspx
  - Template relations
http://demos.telerik.com/aspnet-ajax/grid/examples/hierarchy/nestedviewtemplatedeclarativerelations/defaultcs.aspx
  - Master / Detail grids
http://demos.telerik.com/aspnet-ajax/grid/examples/programming/selectedvalue/defaultcs.aspx

and choose the approach most suitable to your specific requirements.

I hope this will prove helpful.

Regards,
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
Benjamin
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Share this question
or