Hi,
I have a RadGrid that I bind client-side using data from a call to a WCF web service. The call is done via jQuery. Populating the grid with data works ok. However, I want a server-side SelectedIndexChanged event. I do receive the event, but I get an empty SelectedValue property.
The grid is configured as follows:
I use the following AJAX call via jQuery:
And finally my service. I have left out the FindEmployeesResult class, but it's a simple POCO with the correct DataContract and DataMember attributes.
Since the grid has a MasterTableView with DataKeyNames="EmployeeId" and I provide a data source with this property, I would expect the value of EmployeeId to be the SelectedValue of the RadGrid in the gridEmployees_SelectedIndexChanged method. However, it is always empty (to be more precise, it is an instance of System.Object).
How do I make this work as it should?
Kind regards,
Ronald Wildenberg
I have a RadGrid that I bind client-side using data from a call to a WCF web service. The call is done via jQuery. Populating the grid with data works ok. However, I want a server-side SelectedIndexChanged event. I do receive the event, but I get an empty SelectedValue property.
The grid is configured as follows:
| <telerik:RadGrid ID="gridEmployees" runat="server" GridLines="None" AutoGenerateColumns="False" |
| AllowMultiRowSelection="False" OnSelectedIndexChanged="gridEmployees_SelectedIndexChanged" |
| ShowHeader="False" AllowPaging="true" PageSize="20"> |
| <MasterTableView DataKeyNames="EmployeeId"> |
| <Columns> |
| <telerik:GridNumericColumn DataField="EmployeeId" UniqueName="EmployeeId" Visible="false" /> |
| <telerik:GridBoundColumn DataField="FullName" UniqueName="FullName" /> |
| </Columns> |
| </MasterTableView> |
| <ClientSettings EnablePostBackOnRowClick="true"> |
| <ClientEvents OnCommand="gridEmployees_Command" OnMasterTableViewCreated="gridEmployees_MasterTableViewCreated" /> |
| <Selecting AllowRowSelect="true" /> |
| </ClientSettings> |
| <PagerStyle Mode="NumericPages" /> |
| </telerik:RadGrid> |
I use the following AJAX call via jQuery:
| $.ajax({ |
| cache: false, |
| contentType: "application/x-www-form-urlencoded", |
| data: searchData, |
| dataType: "json", |
| type: "GET", |
| url: "/Services/EmployeeService.svc/FindEmployees", |
| success: function(data, textStatus) { |
| var gridEmployees = $find("<%= gridEmployees.ClientID %>"); |
| var employeesTable = gridEmployees.get_masterTableView(); |
| employeesTable.set_dataSource(data.Employees); |
| employeesTable.dataBind(); |
| employeesTable.set_virtualItemCount(data.VirtualItemCount); |
| }, |
| }); |
And finally my service. I have left out the FindEmployeesResult class, but it's a simple POCO with the correct DataContract and DataMember attributes.
| [ServiceContract(Name="EmployeeService", Namespace="Provisior.Services")] |
| [AspNetCompatibilityRequirements( |
| RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] |
| public class EmployeeService |
| { |
| [OperationContract] |
| [WebGet(ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Bare)] |
| public FindEmployeesResult FindEmployees(string searchTerm, int startIndex, int maximumRows) |
| { |
| var employees = new List<EmployeeInfo>(); |
| for (int i = 1; i <= 20; i++) |
| { |
| employees.Add(new EmployeeInfo |
| { |
| EmployeeId = i, |
| FullName = "Employee " + i |
| }); |
| } |
| return new FindEmployeesResult { Employees = employees, VirtualItemCount = 500 }; |
| } |
| } |
Since the grid has a MasterTableView with DataKeyNames="EmployeeId" and I provide a data source with this property, I would expect the value of EmployeeId to be the SelectedValue of the RadGrid in the gridEmployees_SelectedIndexChanged method. However, it is always empty (to be more precise, it is an instance of System.Object).
How do I make this work as it should?
Kind regards,
Ronald Wildenberg