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

[Solved] Client Databind Problem

3 Answers 129 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Josh
Top achievements
Rank 1
Josh asked on 15 Sep 2009, 01:28 AM

I am utilizing client databinding and I cannot get the grid to populate with
anything.  I am returning all my data is JSON format and its verified by
Web Developer Helper.  The grid keeps displaying "No records to display.".
Code is posted below.  Any ideas.

<html xmlns="http://www.w3.org/1999/xhtml" > 
<head runat="server">  
 <title></title>  
</head> 
 <script type="text/javascript">  
     function RebindGrid() {  
         var mtv = $find("<%= RadGrid2.ClientID %>").get_masterTableView();  
         mtv.rebind();  
        return false;  
    }  
    function GridCommand(sender, args) {  
 
    }    
 </script> 
<body> 
<form id="form1" runat="server">  
<asp:ScriptManager id="PlaybookScriptManager" runat="server" /> 
<asp:Button ID="dsd" runat="server" OnClientClick="return RebindGrid();" text="Rebind" /> 
<br /> 
 
<rad:RadGrid runat="server" ID="RadGrid2" AutoGenerateColumns="false" Height="670px" AllowFilteringByColumn="true">  
<MasterTableView DataKeyNames="EventID" ClientDataKeyNames="EventID" Height="670px" > 
<Columns> 
 <rad:GridBoundColumn HeaderText="EventID" DataField="EventID" /> 
 <rad:GridBoundColumn HeaderText="EventName" DataField="EventName" />
</Columns> 
</MasterTableView> 
<ClientSettings> 
 <ClientEvents OnCommand="GridCommand" /> 
 <Scrolling AllowScroll="true" /> 
 <DataBinding Location="Default.aspx" SelectMethod="GetEvents" DataPropertyName="Events"   
 FilterParameterName="filterexp" FilterParameterType="Linq" /> 
 <Selecting AllowRowSelect="true" /> 
</ClientSettings> 
</rad:RadGrid> 
</form> 
</body> 
</html> 
 

[WebMethod]  
        public static Dictionary<stringobject> GetEvents(string filterexp)  
        {  
            var filter = !string.IsNullOrEmpty(filterexp);  
            var data = new DataClasses1DataContext();  
            var events = (from e in data.Events  
                          select new 
                          {  
                              EventID = e.EventID,  
                              EventName = e.EventName  
                          })  
                         .Where(filter ? filterexp : "EventID > 0");  
 
            return new Dictionary<string,object> {{"Events", events}};  
        } 

3 Answers, 1 is accepted

Sort by
0
Sebastian
Telerik team
answered on 17 Sep 2009, 02:06 PM
Hello Josh,

Can you please check whether the OnDataBinding client event of the grid is raised as expected in your case and the data/total items count is passed as explained in the comments of this demo:

http://demos.telerik.com/aspnet-ajax/grid/examples/client/declarativedatabinding/defaultcs.aspx

This should ensure that the grid will visualize the set of records passed in JSON format to it.

Kind regards,
Sebastian
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 18 Sep 2009, 03:56 PM
No, the OnDataBinding client event is not firing.

Joshua
0
Nikolay Rusev
Telerik team
answered on 23 Sep 2009, 01:48 PM
Hello Josh,

Few things that I noticed in your code:
1. You do not have page methods enabled on your ScriptManager;
<asp:ScriptManager ID="PlaybookScriptManager" runat="server"   
EnablePageMethods="true"/

2. You page method does not have proper signature. It should be in your case:
GetEvents(int startRowIndex, int maximumRows, string sortExpression,string filterexp)  
 

and of course RadGrid ClientSettings should be:
<DataBinding Location="Default2.aspx" SelectMethod="GetEvents"   
DataPropertyName="Events" FilterParameterName="filterexp"   
FilterParameterType="Linq" SortParameterType="Linq"/> 

You can check the following example: http://demos.telerik.com/aspnet-ajax/grid/examples/clientbinding/defaultcs.aspx

3. If you are returning Dictionary you should also return Count. For example:
return new Dictionary<stringobject> { { "Events", events },{"Count",10} };  
 


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
Sebastian
Telerik team
Josh
Top achievements
Rank 1
Nikolay Rusev
Telerik team
Share this question
or