in a very very simple client side binding, get_masterTableView(); returns NULL!!!

6 posts, 1 answers
  1. Mohammad sadegh
    Mohammad sadegh avatar
    18 posts
    Member since:
    Jul 2011

    Posted 26 Jul 2011 Link to this post

    Hello All

    i want bind my grid on client side after click on a button, my code is very very simple but when i want catch table view with this code,returns null
    var tableView = $find("<%= RadGrid1.ClientID %>").get_masterTableView();

    this is my full client side code:
    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
     
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
     
    <head runat="server">
        <title></title>
        <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
        <script language="javascript" type="text/javascript">
            function Button1_onclick() {          
                    var tableView = $find("<%= RadGrid1.ClientID %>").get_masterTableView();
                    PageMethods.GetData(1, true, updateGrid);
                }
     
                function updateGrid(result) {
                    var tableView = $find("<%= RadGrid1.ClientID %>").get_masterTableView();
                    tableView.set_dataSource(result);
                    tableView.dataBind();
                }
     
     
        </script>   
        </telerik:RadCodeBlock>
    </head>
    <body>
        <form id="form1" runat="server">
        <input id="Button1" type="button" value="button" onclick="return Button1_onclick()" />
        <telerik:RadScriptManager ID="RadScriptManager1" Runat="server" EnablePageMethods="true">
        </telerik:RadScriptManager>
        <br />
        <telerik:RadGrid ID="RadGrid1" runat="server"  EnableViewState="false">
        <MasterTableView>
            <Columns>
              <telerik:GridBoundColumn DataField="pic" HeaderText="pic" />
            </Columns>
        </MasterTableView>
        </telerik:RadGrid>
        </form>
    </body>
    </html>

    this is my full server side code:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.Services;
    using System.Data;
     
    public partial class Default2 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
     
        }
     
        [WebMethod]
        public static List<object> GetData(int departmentID, bool SelectSubNodesPersonels)
        {
            DAL.Personels ObjPersonels = new DAL.Personels();
            DataTable DT = ObjPersonels.Personels_SELECT_BY_DepartmentID(departmentID, SelectSubNodesPersonels);
     
            return ObjPersonels.Convert_DataTable_To_List_Object(DT);
        }
    }

    what is the problem do you think.

    Special thanks
    Mohammd
  2. Genti
    Admin
    Genti avatar
    107 posts

    Posted 27 Jul 2011 Link to this post

    Hi Mohammad Sadegh,

    That happens as the MasteTable view object does not get created in the first load.
    In order to make the grid load its MasterTableView object you can set some empty data source in the initial load:
    protected override void OnInit(System.EventArgs e)
    {
        base.OnInit(e);
        RadGrid1.NeedDataSource += new Telerik.Web.UI.GridNeedDataSourceEventHandler(RadGrid1_NeedDataSource);
    }
     
    void RadGrid1_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
    {
        RadGrid1.AllowCustomPaging = true;
        RadGrid1.VirtualItemCount = 1000;
        RadGrid1.DataSource = new List<object>();
    }


    Best wishes,
    Genti
    the Telerik team

    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Mohammad sadegh
    Mohammad sadegh avatar
    18 posts
    Member since:
    Jul 2011

    Posted 27 Jul 2011 Link to this post

    Hi Genti

    I found this solution in other post:
    <ClientSettings>
               <ClientEvents OnCommand="function(){}"  />
    </ClientSettings>

    Is it incorrect way to solve my problem?
    It works, but i don't understand what's the relationship between my problem and this solution !

    Best Regards,
    Mohammad
  5. Answer
    Genti
    Admin
    Genti avatar
    107 posts

    Posted 28 Jul 2011 Link to this post

    Hello Mohammad Sadegh,

    Thank you for contacting us.

    Indeed, that tells the RadGrid that you intend to populate it using some client side binding method.
    So, as long as you want to bind the grid client side you are good with that approach.

    The approach that I suggested beforehand has the benefit that on initial load the grid gets populated with data as you can call the WebMethod and handle the NeedDataSource. Then you would need to handle the OnCommand event so that the second time the Grid won't contact the server but instead your web methods.


    Hope this helps.


    Regards,
    Genti
    the Telerik team

    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

  6. Mohammad sadegh
    Mohammad sadegh avatar
    18 posts
    Member since:
    Jul 2011

    Posted 28 Jul 2011 Link to this post

    Thanks my friend Genti.
    You and your team work very well, and you are very creative.

    Good luck.
  7. Lorena
    Lorena avatar
    7 posts
    Member since:
    Mar 2012

    Posted 13 Aug 2013 Link to this post

    Hi,

    Thank you so much, Telerik team, works like a charm.

    Lorena
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017