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

[Solved] Bind RadGrid Client Side to a JSON array

1 Answer 371 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Andre
Top achievements
Rank 1
Andre asked on 20 May 2013, 08:30 PM
Hi! I'm trying to set a small example of binding a RadGrid to a JSON string but I'm not accomplishing it...

Javascript (function gets called on an item click):
function FillTelerikGrid() {
 
        var GridData;
 
        GridData = "{\"Contacts\": {\"Contact\": [{\"ID\": \"1\",\"Name\": \"John Doe\",\"Age\": \"21\",\"Email\": \"johndoe@example.com\"}]}}";
        var tableView = $find("<%= RadGrid1.ClientID %>").get_masterTableView();
        tableView.set_dataSource(GridData);
        tableView.dataBind();
 
}

Control.ascx
       <div id="<%=this.ClientID%>_ContextContainer" class="divContextContainer"
           style="float: left; height: 400px; overflow-y: auto; width: 33.3%;">  
<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="false" Skin="Metro">
               <MasterTableView>
                   <Columns>
                       <telerik:GridBoundColumn DataField="ID" UniqueName="ID" HeaderText="ID">
                       </telerik:GridBoundColumn>
                   </Columns>
               </MasterTableView>
           </telerik:RadGrid>
       </div>


Control.ascx.cs
protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                if (!IsPostBack)
                {
                    dynamic data = new[] {
                        new { ID = "1", Name ="Name11",Age = "0"},
                        new { ID = "2", Name ="Name11",Age = "0"},
                        new { ID = "3", Name ="Name11",Age = "0"},
                        new { ID = "4", Name ="Name11",Age = "0"}
                    };
                    RadGrid1.MasterTableView.DataSource = data;
                    RadGrid1.DataBind();
                }
 
            }
            catch (Exception ex)
            {
                Platform.WebUI.DiagnosticsHelper.ReportError(ex);
                throw ex;
            }
        }


I based my code on the one i found on this post: http://www.telerik.com/community/forums/aspnet-ajax/grid/bind-radgrid-client-side-to-a-json-array.aspx

But, I'm getting the following Javascript exception:

On Chrome, I get:
Uncaught TypeError: Cannot read property 'style' of null ScriptResource.axd:6507
Telerik.Web.UI.RadGrid._getAllChildItemsRecursive ScriptResource.axd:6507
Telerik.Web.UI.RadGrid._getPositionedDataItems ScriptResource.axd:6499
Telerik.Web.UI.GridTableView.dataBind ScriptResource.axd:3831
FillTelerikGrid Notes.aspx:695
getContextView Notes.aspx:637
(anonymous function) Notes.aspx:608
f.event.dispatch jquery.js:3
h.handle.i

On Firefox I get:
[21:29:29.778] TypeError: m.get_element(...).parentNode.parentNode is null @ https://www.....(...)

P.S.: I didn't add RadScriptManager because the portal already has a ScriptManager... Don't know if that is the problem...

1 Answer, 1 is accepted

Sort by
0
Andre
Top achievements
Rank 1
answered on 21 May 2013, 01:51 PM
My mistake. I had a function removing the container div childs before the call to the function. Now it is working.
Tags
Grid
Asked by
Andre
Top achievements
Rank 1
Answers by
Andre
Top achievements
Rank 1
Share this question
or