<ClientSettings>
<DataBinding SelectMethod="GetDataAndCount" Location="../Services/RecordService.svc" SortParameterType="Linq"
FilterParameterType="Linq" CountPropertyName="Count">
</DataBinding>
</ClientSettings
>
I can not send the extra search fields to the service and rebind the grid without having to do a full page post back.
My Service looks like
public ResultData<Record> GetDataAndCount(int startRowIndex, int maximumRows, string sortExpression, string
filterExpression)
I want it to look something along these lines
public ResultData<Record> GetDataAndCount(int startRowIndex, int maximumRows, string sortExpression, string filterExpression, RecrodSearchCriteria
criteria)
Any help would be greatly appreciated. This will make or break my decision to go with Telerik controls or not.
Thanks
Bullish
7 Answers, 1 is accepted
I looked at your solution before I posted my question, but that seems like a work around rather than a inherent solution to the problem.
Doe the grid support passing extra parameters inherently, like the jqgrid does.
The closest I got was using the onDataBinding client side function, and setting the arguments... but I can't seem to rebind the client side grid to the service again without doing a full post back.
Thanks
Bullish
Can you please provide your code to resolved the issue ?
Thanks, Jayesh Goyani
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="default.aspx.cs" Inherits="GridTest._default" %>
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<!DOCTYPE html>
<
html
xmlns
=
"http://www.w3.org/1999/xhtml"
>
<
head
runat
=
"server"
>
<
title
></
title
>
<
asp:PlaceHolder
ID
=
"PlaceHolder1"
runat
=
"server"
>
<
script
>
function buttonClick() {
$find('<%=RadGrid1.ClientID %>').get_masterTableView().rebind();
}
function RadGrid1_DataBinding(sender, args) {
var searchField = document.getElementById('<%=txtName.ClientID%>').value;
var arguments = args.get_methodArguments();
arguments.criteria = { Name: searchField };
args.set_methodArguments(arguments);
}
</
script
>
</
asp:PlaceHolder
>
</
head
>
<
body
>
<
form
id
=
"form1"
runat
=
"server"
>
<
telerik:RadScriptManager
ID
=
"RadScriptManager1"
runat
=
"server"
></
telerik:RadScriptManager
>
<
div
>
<
div
>
<
label
>Search Name</
label
><
asp:TextBox
runat
=
"server"
ID
=
"txtName"
/>
<
br
/>
<
input
type
=
"button"
value
=
"Try to submit without submiting page"
onclick
=
"buttonClick();"
/>
<
br
/>
<
input
type
=
"submit"
value
=
"submit page"
/>
</
div
>
<
div
>
<
telerik:RadGrid
ID
=
"RadGrid1"
runat
=
"server"
AllowSorting
=
"true"
EnableViewState
=
"false"
ClientSettings-DataBinding-EnableCaching
=
"true"
AllowPaging
=
"true"
PageSize
=
"25"
PagerStyle-AlwaysVisible
=
"true"
AllowFilteringByColumn
=
"true"
AutoGenerateColumns
=
"false"
>
<
MasterTableView
ClientDataKeyNames
=
"Name"
IsFilterItemExpanded
=
"false"
>
<
PagerStyle
Mode
=
"NextPrevAndNumeric"
/>
<
Columns
>
<
telerik:GridBoundColumn
DataField
=
"Name"
HeaderText
=
"Name"
UniqueName
=
"Name"
DataType
=
"System.String"
SortExpression
=
"Name"
/>
<
telerik:GridBoundColumn
DataField
=
"Address"
HeaderText
=
"Address"
UniqueName
=
"Address"
DataType
=
"System.String"
/>
</
Columns
>
</
MasterTableView
>
<
ClientSettings
>
<
ClientEvents
OnDataBinding
=
"RadGrid1_DataBinding"
/>
<
DataBinding
SelectMethod
=
"GetDataAndCount"
Location
=
"Test.svc"
SortParameterType
=
"Linq"
FilterParameterType
=
"Linq"
CountPropertyName
=
"Count"
>
</
DataBinding
>
</
ClientSettings
>
</
telerik:RadGrid
>
</
div
>
</
div
>
</
form
>
</
body
>
</
html
>
namespace
GridTest
{
[ServiceContract]
public
interface
ITest
{
[OperationContract]
[WebInvoke(Method =
"POST"
, BodyStyle = WebMessageBodyStyle.WrappedRequest, ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json)]
ResultData<SampleData> GetDataAndCount(
int
startRowIndex,
int
maximumRows,
string
sortExpression,
string
filterExpression, SearchCriteria criteria);
}
[DataContract]
public
class
SearchCriteria
{
[DataMember]
public
string
Name {
get
;
set
; }
}
[DataContract]
public
class
SampleData
{
[DataMember]
public
string
Name {
get
;
set
; }
[DataMember]
public
string
Address {
get
;
set
; }
}
public
class
ResultData<T>
{
public
ResultData()
{
Data =
new
List<T>();
}
public
int
Count {
get
;
set
; }
public
List<T> Data {
get
;
set
; }
}
public
class
Test : ITest
{
ResultData<SampleData> _data;
public
Test()
{
_data =
new
ResultData<SampleData>();
_data.Data.Add(
new
SampleData { Name =
"Sam"
, Address =
"New York, USA"
});
_data.Data.Add(
new
SampleData { Name =
"John"
, Address =
"Virginia, USA"
});
_data.Data.Add(
new
SampleData { Name =
"Jack"
, Address =
"California, USA"
});
_data.Count = _data.Data.Count();
}
public
ResultData<SampleData> GetDataAndCount(
int
startRowIndex,
int
maximumRows,
string
sortExpression,
string
filterExpression, SearchCriteria criteria)
{
ResultData<SampleData> returnVal =
new
ResultData<SampleData>();
if
(criteria !=
null
&& !
string
.IsNullOrWhiteSpace(criteria.Name))
{
returnVal.Data = _data.Data.Where(c => c.Name.ToUpper().Contains(criteria.Name.ToUpper())).ToList();
returnVal.Count = returnVal.Data.Count();
}
else
{
returnVal = _data;
}
return
returnVal;
}
}
}
<
system.serviceModel
>
<
bindings
>
<
webHttpBinding
>
<
binding
name
=
"RestServiceBinding"
crossDomainScriptAccessEnabled
=
"true"
allowCookies
=
"false"
useDefaultWebProxy
=
"true"
maxReceivedMessageSize
=
"2147483647"
maxBufferPoolSize
=
"2147483647"
hostNameComparisonMode
=
"StrongWildcard"
bypassProxyOnLocal
=
"false"
sendTimeout
=
"00:35:00"
receiveTimeout
=
"00:35:00"
openTimeout
=
"00:35:00"
closeTimeout
=
"00:35:00"
>
<
readerQuotas
maxNameTableCharCount
=
"2147483647"
maxBytesPerRead
=
"2147483647"
maxArrayLength
=
"2147483647"
maxStringContentLength
=
"2147483647"
maxDepth
=
"2147483647"
/>
<
security
mode
=
"None"
/>
</
binding
>
</
webHttpBinding
>
</
bindings
>
<
behaviors
>
<
endpointBehaviors
>
<
behavior
name
=
"RestEndpointBehaviour"
>
<
webHttp
helpEnabled
=
"true"
defaultOutgoingResponseFormat
=
"Json"
automaticFormatSelectionEnabled
=
"false"
faultExceptionEnabled
=
"true"
/>
</
behavior
>
</
endpointBehaviors
>
<
serviceBehaviors
>
<
behavior
name
=
"CommonServiceBehaviour"
>
<
serviceMetadata
httpGetEnabled
=
"true"
/>
<
serviceDebug
includeExceptionDetailInFaults
=
"true"
/>
</
behavior
>
<
behavior
name
=
""
>
<
serviceMetadata
httpGetEnabled
=
"true"
httpsGetEnabled
=
"true"
/>
<
serviceDebug
includeExceptionDetailInFaults
=
"false"
/>
</
behavior
>
</
serviceBehaviors
>
</
behaviors
>
<
services
>
<
service
name
=
"GridTest.Test"
behaviorConfiguration
=
"CommonServiceBehaviour"
>
<
endpoint
behaviorConfiguration
=
"RestEndpointBehaviour"
bindingConfiguration
=
"RestServiceBinding"
contract
=
"GridTest.ITest"
binding
=
"webHttpBinding"
address
=
""
></
endpoint
>
</
service
>
</
services
>
<
serviceHostingEnvironment
aspNetCompatibilityEnabled
=
"true"
multipleSiteBindingsEnabled
=
"true"
/>
</
system.serviceModel
>
How can I get the first button to hit the service again to get to the service, and pass the arguments the way I'm passing them in the second button.
Thanks
Bullish.
I was not able to download the project from the provided link as the download quota is exceeded. Could you please upload it again? Note that additional parameters could not be added to the service and as a workaround you could use the Jayesh's approach.
Regards,
Kostadin
Telerik