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

[Solved] Client-side binding with dynamic grid?

1 Answer 141 Views
Grid
This is a migrated thread and some comments may be shown as answers.
m f
Top achievements
Rank 1
m f asked on 21 Oct 2009, 04:55 PM
Hello,
    I was wondering if it is possible to bind a grid client-side when it has been generated on the server with the use of GridTemplateColumns and ItemTemplateColumns.  This is currently not working for me.  Am I missing something or is this functionality simply not supported?  Is the grid binding but not updating on the page?  When I try to do the client-side binding on a grid that has simply been dropped on the page it does work.
Thanks very much in advance!

This is my code:

var weeks = null
var tableView = null;

        function pageLoad(sender, args)

        {
                $.ajax({

 

                    type: "POST",

                    url: "test.aspx/GetData",

                    data: "{}",

                    contentType: "application/json; charset=utf-8",

                    dataType: "json",

                    success: refreshControls,

                    fail: onFail

                });

 

        }

 

        function refreshControls(result)

        {

            weeks = eval(result.d); 

        }

        function GridCreated(sender, eventArgs) {

           

            if (sender.Control.id == "<%= Grid1.ClientID %>")

                tableView = $find("<%= Grid1.ClientID %>").get_masterTableView();

              

        }

        function ReDrawGrid()

        {

            weeks[0].amount = 82;

            tableView.set_dataSource(weeks);

            tableView.dataBind();

        }

On Server

 

private void DefineGridStructure(int columnCount)

        {

            Grid1.AutoGenerateColumns = false;

            Grid1.AllowSorting = false;

            Grid1.AllowPaging = false;

            Grid1.GridLines = GridLines.None;

            Grid1.NeedDataSource += new GridNeedDataSourceEventHandler(doiGrid_NeedDataSource);

            Grid1.ClientSettings.ClientEvents.OnGridCreated = "GridCreated";

            //scrolling

            Grid1.ClientSettings.Scrolling.AllowScroll = true;

            Grid1.ClientSettings.Scrolling.UseStaticHeaders = true;

            //Master Table

            Grid1.MasterTableView.TableLayout = GridTableLayout.Fixed;

            Grid1.MasterTableView.HierarchyLoadMode = GridChildLoadMode.Client;

            Grid1.Width = Unit.Pixel(columnCount * 88);

            Grid1.Height = Unit.Pixel(126);

            //Columns

            GridTemplateColumn templateColumn = new GridTemplateColumn();

            templateColumn.AllowFiltering = false;

            templateColumn.ShowFilterIcon = false;

            templateColumn.HeaderTemplate = new HeaderTemplate(columnCount);

            templateColumn.ItemTemplate = new ItemTemplate(columnCount);

            Grid1.MasterTableView.Columns.Add(templateColumn);

 

        }

 

1 Answer, 1 is accepted

Sort by
0
Tsvetoslav
Telerik team
answered on 27 Oct 2009, 07:51 AM
Hello m f,

There is no difference whether the grid is generated in mark-up or in code-behind - you just need to do it correctly. A demonstration of this scenario can be found at the following online example and the related help topics:
http://demos.telerik.com/aspnet-ajax/grid/examples/hierarchy/definingstructure/defaultcs.aspx


Best wishes,
Tsvetoslav
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
Grid
Asked by
m f
Top achievements
Rank 1
Answers by
Tsvetoslav
Telerik team
Share this question
or