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

[Solved] Client OnDataBinding Event not firing

3 Answers 434 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Josh
Top achievements
Rank 1
Josh asked on 18 Sep 2009, 11:46 PM

I am trying to use programmatic client side binding with my grid, however,
the grid keeps saying "No records to display.".  Below is my code.  Does
anyone see why it is not populating my grid?  I have verified that I do get
my data passed back in JSON format in the correct Method Names.

Oh yeah, when the grid first comes up it has paging enable, but
after the button click and grid.dataBind is does not.

I was thinking it was the OnDataBinding() handler because at
first I was not using the standard SelectMethod and Count Names.
Still doesn't work though.

<script type="text/javascript">  
var tableview;  
 
    function pageLoad() {  
        tableview=$find("Grid").get_masterTableView();  
    }  
    function ButtonClick(sender, args) {  
        PageMethods.GetEvents(0, 100, """",GetData);  
        return false;  
    }  
    function GetData(Data) {  
        tableview.set_dataSource(Data);  
        tableview.dataBind();  
    }  
    function Grid_DataBinding(sender, args) {  
        alert("Made it this far.");  
        sender.ClientSettings.DataBinding.SelectMethod = "GetData";  
        sender.ClientSettings.DataBinding.SelectCountMethod = "GetCount";  
        sender.ClientSettings.DataBinding.FilterParameterType = "Linq";  
        sender.ClientSettings.DataBinding.SortParameterType = "Linq";  
    }  
</script> 

<asp:ScriptManager ID="MainScript" runat="server" EnablePageMethods="true" /> 
    <asp:Button ID="Button1" runat="server" Text="Get Data" OnClientClick="return ButtonClick();" /> 
    <rad:RadGrid runat="server" ID="Grid" AutoGenerateColumns="false" Height="670px" AllowPaging="true"   
    PageSize="15" Skin="Telerik">  
    <MasterTableView TableLayout="Fixed" ClientDataKeyNames="EventID,EventName" Height="670px">  
   <Columns> 
    <rad:GridBoundColumn HeaderText="EventID" DataField="EventID" /> 
    <rad:GridBoundColumn HeaderText="EventID" DataField="EventName" /> 
   </Columns> 
   </MasterTableView> 
   <ClientSettings> 
 <ClientEvents OnCommand="function(){}" OnDataBinding="Grid_DataBinding" /> 
 <Scrolling AllowScroll="true" /> 
 <Selecting AllowRowSelect="true" /> 
</ClientSettings> 
</rad:RadGrid> 

        [WebMethod]  
        public static Dictionary<stringobject> GetEvents(int startRowIndex, int maximumRows, string sortExpression, string filterExpression)  
        {  
            var filter = !string.IsNullOrEmpty(filterExpression);  
            var sort = !string.IsNullOrEmpty(sortExpression);  
 
            var data = new LinqtoSqlDataContext();  
            var eventdata = (from e in data.Events  
                             select new 
                             {  
                                 EventID = e.EventID,  
                                 EventName = e.EventName  
                             })  
                         .Where(filter ? filterExpression : "EventID > 0")  
                         .OrderBy(sort ? sortExpression : "EventID ASC");  
 
            var count = filter ? eventdata.Count() : data.Events.Count();  
            eventdata = eventdata.Skip(startRowIndex).Take(maximumRows);  
            return new Dictionary<stringobject> { { "GetData", eventdata }, { "GetCount", count } };  
        } 

3 Answers, 1 is accepted

Sort by
0
Nikolay Rusev
Telerik team
answered on 23 Sep 2009, 03:17 PM
Hello Josh,

Your page method should return Dictionary that has key "Data" with value data source items for RadGrid and another key "Count" with total row count, instead of "GetData" and "GetCount".

return new Dictionary<stringobject> { { "Data", eventdata }, { "Count", count } };     
 


Regards,
Nikolay
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.
0
Josh
Top achievements
Rank 1
answered on 23 Sep 2009, 03:50 PM
Nikolay,

 Should I not be able to declare the method names I wish to use on the
WebMethod return in the OnDataBinding Event on the client?  My whole
point is that the event is not firing.

Joshua
0
Nikolay Rusev
Telerik team
answered on 24 Sep 2009, 06:24 AM
Hello Josh,

Please go through the following examples for more details:
http://demos.telerik.com/aspnet-ajax/grid/examples/clientbinding/defaultcs.aspx
http://demos.telerik.com/aspnet-ajax/grid/examples/client/databinding/defaultcs.aspx
http://demos.telerik.com/aspnet-ajax/grid/examples/client/declarativedatabinding/defaultcs.aspx

You should notice the following settings:
DataBinding.SelectMethod - setups the name of service method that will return the data
DataBinding.DataPropertyName - setups the name of the property in your dictionary that holds serialized JSON.

You should also try the suggestions in this forum thread: http://www.telerik.com/community/forums/aspnet-ajax/grid/client-databind-problem.aspx

All the best,
Nikolay
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
Josh
Top achievements
Rank 1
Answers by
Nikolay Rusev
Telerik team
Josh
Top achievements
Rank 1
Share this question
or