Im currently trying to fill a grid using webservice call.
The thing is a need to send an extra parameter to the webservice aside from the filters allowed by the grid.
Is there anyway of doing this?
Cheers
5 Answers, 1 is accepted
I am not sure I understand your question. You can sand as many arguments to your web service as defined by the parameters of the remote web service method you are calling. Can you, please, clarify.
Greetings,
Veli
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
This is the webmethod which we are usign
[WebMethod]
[System.Web.Script.Services.ScriptMethod(ResponseFormat = System.Web.Script.Services.ResponseFormat.Json)]
public PagedQueryResult SelectEntityDataAndCount(int startRowIndex, int maximumRows, string sortExpression, string filterExpression)
{
string entity = HttpContext.Current.Request.QueryString.Get("entity");
EntitiesDataService entitiesDataService = new EntitiesDataService();
return entitiesDataService.SelectEntityDataAndCount(entity, startRowIndex, maximumRows, sortExpression, filterExpression);
}
It goes to the database and selects and recovers some data. The database table it uses on the select statement is defined on the parameter passed on in the querystring. (aka entity)
We have a control which inherits from the radgrid, thats going to display the data and has some properties configured
ClientSettings.DataBinding.Location = "EntitiesService.asmx";
ClientSettings.DataBinding.FilterParameterType = GridClientDataBindingParameterType.Linq;
ClientSettings.DataBinding.SortParameterType = GridClientDataBindingParameterType.Linq;
We were wondering if we could use some web service method like this
[WebMethod]
[System.Web.Script.Services.ScriptMethod(ResponseFormat = System.Web.Script.Services.ResponseFormat.Json)]
public PagedQueryResult SelectEntityDataAndCount(string entity, int startRowIndex, int maximumRows, string sortExpression, string filterExpression)
{
EntitiesDataService entitiesDataService = new EntitiesDataService();
return entitiesDataService.SelectEntityDataAndCount(entity, startRowIndex, maximumRows, sortExpression, filterExpression);
}
If this kind of scenario is possible, how can we set the client configuration from the ascx definition, specifically the entity parameter (like when you're using an object datasource, where you can configure the parameter value source -another webcontrol value, a querystring value, a cookie value, and so on-)? Or the webmethod signature is non flexible? :S
Thanks
Cheers
Thank you for the detailed description. Unfortunately, using the Location property to specify a web service location and SelectMethod to specify the select method cannot be extended to additionally pass custom parameters. You will need to manually call the method with your custom parameter, retrieve the data and bind your grid. This is all described in the second part (Non-declarative client-side binding) of the client-side databinding help article and related demos.
Regards,
Veli
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Well I suppose doing it from javascript is not that bad. I just tought there was a more elegant aproach.
Thanks! :)
Hi folks,
It's maybe late for this message but it can help someone. I am really a beginner, looking at this great grid for 3-4 days and had this problem as well.
I just tried this crazy solution and it seems to be working (this message formatting is killing me, always adds some extra lines...)
public partial class _Default : System.Web.UI.Page
{
[WebMethod]
public static IEnumerable GetProducts(int startRowIndex, int maximumRows)
{
string reqID = HttpContext.Current.Request.QueryString.Get("ReqID");
var northwind = new NorthwindDataContext();
var products = from p in northwind.Products
select new
{
ProductID = p.ProductID,
Name = p.ProductName,
CategoryName = p.Category.CategoryName
};
return products.Skip(startRowIndex).Take(maximumRows);
}
[WebMethod]
public static int GetProductCount()
{
string reqID = HttpContext.Current.Request.QueryString.Get("ReqID");
string candID = HttpContext.Current.Request.QueryString.Get("CandID");
var northwind = new NorthwindDataContext();
var count = northwind.Products.Count();
return count;
}
}
and grid declaration, adding extra parameters like this
<DataBinding Location="Default.aspx" SelectMethod="GetProducts?ReqID=10"
SelectCountMethod="GetProductCount?ReqID=10&CandID=20">
<telerik:RadGrid ID="RadGrid2" runat="server" AllowPaging="True"
AllowSorting="True" GridLines="None"
Skin="Sunset" Height="400px"
AllowFilteringByColumn="True"
AllowMultiRowSelection="True" EnableViewState="False">
<MasterTableView EnableViewState="False" AutoGenerateColumns="false">
<RowIndicatorColumn>
<HeaderStyle Width="20px"></HeaderStyle>
</RowIndicatorColumn>
<ExpandCollapseColumn>
<HeaderStyle Width="20px"></HeaderStyle>
</ExpandCollapseColumn>
<Columns>
<telerik:GridClientSelectColumn ItemStyle-Width="60px"></telerik:GridClientSelectColumn>
<telerik:GridBoundColumn DataField="ProductID" HeaderText="ID" Resizable="true" ItemStyle-Width="120px"></telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Name" HeaderText="Name" Resizable="true"></telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="CategoryName" HeaderText="Category" Resizable="true"></telerik:GridBoundColumn>
</Columns>
</MasterTableView>
<ClientSettings>
<Selecting AllowRowSelect="true" />
<DataBinding Location="Default.aspx" SelectMethod="GetProducts?ReqID=10"
SelectCountMethod="GetProductCount?ReqID=10&CandID=20">
</DataBinding>
</ClientSettings>
</telerik:RadGrid>
Thanks,
Radovan