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<string, object> 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<string, object> { { "GetData", eventdata }, { "GetCount", count } }; |
| } |