I have a grid control which I have enabled client-side binding using a web service as the datasource.
At the bottom of the form, I have a button to post the results of the client-side selection. How can I retrieve the results of the client-side selection on the server postback?
I have attempted the following code, but text returns " ". If the Grid has no selection, the SectedItems count is 0 and if one item is selected the count is 1, but I am not sure how to retrieve the PrimaryKey or cell from the selected item.
Any ideas what I am missing?
| <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server"> |
| <script type="text/javascript"> |
| function RadGrid1_DataBinding(sender, args) { |
| // This event will be raised twice by default! |
| // The first call will retrieve data and the second call will retrieve total items count. |
| // If you want to cancel the event you can use: |
| // args.set_cancel(true); |
| // get data source location, method name and arguments |
| var dataSourceLocation = args.get_location(); |
| var selectMethodName = args.get_methodName(); |
| var methodArguments = args.get_methodArguments(); |
| // set data source location and method name |
| // args.set_location("url to your data source"); |
| // args.set_methodName("your method name"); |
| // The grid will always pass by default four arguments for the SelectMethod. |
| // SelectCountMethod will be called with no arguments by default! |
| // get names for select parameters |
| var startRowIndexParameterName = sender.ClientSettings.DataBinding.StartRowIndexParameterName; |
| // default is "startRowIndex". |
| var maximumRowsParameterName = sender.ClientSettings.DataBinding.MaximumRowsParameterName; |
| // default is "maximumRows" |
| var sortParameterName = sender.ClientSettings.DataBinding.SortParameterName; |
| // default is "sortExpression" |
| var filterParameterName = sender.ClientSettings.DataBinding.FilterParameterName; |
| // default is "filterExpression" |
| // construct your own arguments |
| // var myMethodArguments = new Object(); |
| // myMethodArguments.myArgumentName = "myArgumentValue"; |
| // args.set_methodArguments(myMethodArguments); |
| } |
| function RowSelected(row, eventArgs) { |
| var grid = $find("<%=RadGridService.ClientID %>").get_masterTableView(); |
| grid.rebind(); |
| } |
| </script> |
| </telerik:RadCodeBlock> |
| <telerik:RadGrid ID="RadGrid1" AllowSorting="True" AllowPaging="True" |
| AutoGenerateColumns="False" runat="server" GridLines="None" Width="653px" |
| onneeddatasource="RadGrid1_NeedDataSource" > |
| <MasterTableView> |
| <Columns> |
| <telerik:GridBoundColumn DataField="ID" HeaderText="ID" DataType="System.Int32" /> |
| <telerik:GridBoundColumn DataField="FirstName" HeaderText="FirstName" /> |
| <telerik:GridBoundColumn DataField="LastName" HeaderText="LastName" /> |
| </Columns> |
| </MasterTableView> |
| <PagerStyle AlwaysVisible="true" /> |
| <ClientSettings EnablePostBackOnRowClick="True" > |
| <ClientEvents OnDataBinding="RadGrid1_DataBinding" /> |
| <DataBinding Location="Services.asmx" |
| SelectMethod="GetData" SelectCountMethod="GetCount" /> |
| <Selecting AllowRowSelect="True" /> |
| <ClientEvents OnRowSelected = "RowSelected"/> |
| </ClientSettings> |
| </telerik:RadGrid> |
At the bottom of the form, I have a button to post the results of the client-side selection. How can I retrieve the results of the client-side selection on the server postback?
I have attempted the following code, but text returns " ". If the Grid has no selection, the SectedItems count is 0 and if one item is selected the count is 1, but I am not sure how to retrieve the PrimaryKey or cell from the selected item.
| protected void Button1_Click(object sender, EventArgs e) |
| { |
| GridItemCollection selectedItems = RadGrid1.SelectedItems; |
| foreach (GridItem selectedItem in selectedItems) |
| { |
| string text = ((GridDataItem)selectedItem)["LastName"].Text; |
| } |
| } |
Any ideas what I am missing?