GridTemplateColumn empty when RadGrid bound with JSON data on client side

4 posts, 0 answers
  1. Rob
    Rob avatar
    23 posts
    Member since:
    Apr 2013

    Posted 20 Dec 2013 Link to this post

    Hi,
    I am trying to bind RadGrid with JSON Data on Client side. GridBoundColumns display data ok, but GridTemplateColumn is empty.
    My code is below. Please, help.

    <
    telerik:GridTemplateColumn UniqueName="Description" DataField=Description" AllowFiltering="false" >
         <ItemTemplate>
             <asp:Label ID="Description" runat="server"  />
         </ItemTemplate>
    </telerik:GridTemplateColumn>
     
     $.ajax({
     
                    type: 'POST',
     
                    contentType: 'application/json; charset=utf-8',
     
                    data: '{}',
     
                    dataType: 'JSON',
                    url: '../../Services/Service.svc/GetList',
                    success: function (result) {
                     var GridData = result.GetListResult;
                     if (GridData.length > 0) {
                         var masterTable = $find("<%=gvList.ClientID %>").get_masterTableView();
                         masterTable.set_dataSource(GridData);
                         masterTable.dataBind();
    }
  2. Jayesh Goyani
    Jayesh Goyani avatar
    2732 posts
    Member since:
    May 2010

    Posted 20 Dec 2013 Link to this post

    Hello,

    You have to create DOM manually for Template control.

    <telerik:GridTemplateColumn UniqueName="Description" DataField=Description" AllowFiltering="false" >
         <ItemTemplate>
             <asp:Label ID="Description" runat="server"  />
         </ItemTemplate>
    </telerik:GridTemplateColumn>

    <script>
                function RowDataBound(sender, args) {
                    var celName = args.get_item().get_cell("Description");
                    var input = document.createElement("span");
                          input.innerHTML = args.get_dataItem().Description;
        
                    celName.appendChild(input);
                }
            </script>

    Let me know if any concern.

    Thanks,
    Jayesh Goyani
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Rob
    Rob avatar
    23 posts
    Member since:
    Apr 2013

    Posted 23 Dec 2013 Link to this post

    Hi, Jayesh,

    Thank you for the response. The code that you provided doesn't work for me. I am getting error: celName is null.

    Please help.
  5. Eyup
    Admin
    Eyup avatar
    3015 posts

    Posted 25 Dec 2013 Link to this post

    Hi Rob,

    Please try to use ClientItemTemplate provided by RadGrid and let me know about the result:
    http://demos.telerik.com/aspnet-ajax/grid/examples/data-binding/client-side/client-item-template/defaultcs.aspx

    Looking forward to your reply.

    Regards,
    Eyup
    Telerik
    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 the blog feed now.
Back to Top