开发者

How to pass data to an Ajax Service using Telerik Rad Grid Binding?

I have a Telerik RadGrid in which I'm implementing custom paging binding to a Ajax Service. How do you pass data like a Search String to the Web Method?

The Mark up looks something like this:

 <telerik:RadGrid ID="radGridProviders" runat="server" AllowPaging="T开发者_StackOverflow社区rue" PageSize="10" AutoGenerateColumns="false" >
    <PagerStyle Mode="NextPrevAndNumeric" />
    <MasterTableView TableLayout="Fixed" >
        <Columns>
            ...
        </Columns>
    </MasterTableView>
    <ClientSettings>
        <Scrolling AllowScroll="True" EnableVirtualScrollPaging="True" UseStaticHeaders="True">
        </Scrolling>
        <DataBinding Location="/AjaxServices/SearchService" SelectMethod="GetProductData" SelectCountMethod="GetProductCount" StartRowIndexParameterName="startRowIndex" MaximumRowsParameterName="maxRows" />
        <ClientEvents OnCommand="showLoadingPanel" OnDataBound="hideLoadingPanel" />
        </ClientSettings>
    </telerik:RadGrid>

I want to pass to my Service a search string and/or other customer parameters How do I do it with the RadGrid Binding?

My service that responds to the requests is an ASP.NET MVC Controller. The service responds fine to requests from the browser. My problem is that I don't know how to pass custom data using the Telerik binding features.

public class SearchServiceController : Controller
{
    private ISearchController _searchController;

    public SearchServiceController(ISearchController searchController)
    {
        _searchController = searchController;
    }

    public int GetProductCount()
    {
        int returnValue = 0;

        // brevity brevity

        return returnValue ;
    }

    public List<SearchProviders_Result> GetProductData(int startRowIndex, int maxRows)
    {

           // brevity brevity

    }
}

Any Suggestions?


This is what I found with a little help from Telerik Support.

In the ClientSetting of the RadGrid add a method to the ClientEvents OnDataBinding. My name method name is OnClientDataBinding in this example

Then create the client method:

            // This OnClient DataBinding builds the arguments uses to call the 
            // Ajax Service used to retrieve that when needed.
            function OnClientDataBinding(sender, args) {

                // get data source location, method name and arguments
                var dataSourceLocation = args.get_location();
                var selectMethodName = args.get_methodName();
                var methodArguments = args.get_methodArguments();

            ...  

I actually modified the sortExpression and fitlerExpresion and these are passed as an Array.

        // construct arguments for Ajax Service
        var myMethodArguments = new Object();
        myMethodArguments.startRowIndex = methodArguments.startRowIndex;
        myMethodArguments.maximumRows = methodArguments.maximumRows;
        myMethodArguments.sortExpression = sortExpression;
        myMethodArguments.filterExpression = filterExpression;
        myMethodArguments.myParam1 = "David";
        myMethodArguments.myParam2 = 14926;

        args.set_methodArguments(myMethodArguments);
    }

Then create your Service Controller Method something like:

public JsonResult GetCustomerSearchResults(int startRowIndex, int maximumRows, string sortExpression, FilterExpression[] filterExpression, string myParam1, int myParam2)
    {
        IEnumerable results;

        ... fill your Data and Count. 

        return Json(new { Data = results.ToList(), Count = totalNumberOfRows });
    }

FilterExpression[] is an object that I created for my use. This is not a Telerik object.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜