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

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

6 Answers 893 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mohammad sadegh
Top achievements
Rank 1
Mohammad sadegh asked on 26 Jul 2011, 07:05 PM
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

6 Answers, 1 is accepted

Sort by
1
Genti
Telerik team
answered on 27 Jul 2011, 01:59 PM
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.

0
Mohammad sadegh
Top achievements
Rank 1
answered on 27 Jul 2011, 05:00 PM
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
0
Accepted
Genti
Telerik team
answered on 28 Jul 2011, 01:45 PM
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.

0
Mohammad sadegh
Top achievements
Rank 1
answered on 28 Jul 2011, 03:01 PM
Thanks my friend Genti.
You and your team work very well, and you are very creative.

Good luck.
0
Lorena
Top achievements
Rank 1
answered on 13 Aug 2013, 04:38 PM
Hi,

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

Lorena
0
Mukku
Top achievements
Rank 1
answered on 18 Mar 2017, 01:27 PM

Hi,

I am having a similar problem, I am binding the Radgrid on the server side, I can see the data bound to the grid.

I need to export the data in the grid to excel, When I try to execute the following code, I get the "get_masterTableView" as undefined:

var masterTable = $find("<%= RadGrid1.ClientID %>").get_masterTableView();

masterTable.exportToExcel();

I want to export the grid data to excel

Please suggest

Tags
Grid
Asked by
Mohammad sadegh
Top achievements
Rank 1
Answers by
Genti
Telerik team
Mohammad sadegh
Top achievements
Rank 1
Lorena
Top achievements
Rank 1
Mukku
Top achievements
Rank 1
Share this question
or