This is a migrated thread and some comments may be shown as answers.

[Solved] how to hook up grid to webservice

2 Answers 117 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Darren
Top achievements
Rank 2
Darren asked on 30 Jun 2009, 12:16 PM
Hi there,

I've wired up my radgrid to run off a webservice in the code behind file.
But when I create a webservice and place it into a different location then my radgrid doesn't populate. I'm obviously not connecting it properly.

Here is my ASPX:
            <ClientSettings> 
                <DataBinding Location="Default.aspx" SelectCountMethod="GetProductCount" SelectMethod="GetProducts"
                </DataBinding> 
                <Selecting AllowRowSelect="True" /> 
            </ClientSettings> 

That works but if I change Location="Default.aspx" to Location="Products.asmx" then my grid doesn't populate.

Here is my Products.asmx:
[WebService(Namespace = "Products")] 
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] 
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.  
[System.Web.Script.Services.ScriptService] 
public class Products : System.Web.Services.WebService { 
 
    [WebMethod] 
    public static IEnumerable GetProducts(int startRowIndex, int maximumRows) 
    { 
        var northwind = new NorthwindDataContext(); 
        var products = from p in northwind.Products 
                       select new 
                       { 
                           ProductID = p.ProductID, 
                           Name = p.ProductName, 
                           CategoryName = p.Category.CategoryName, 
                           Price = p.UnitPrice, 
                           UnitsInStock = p.UnitsInStock 
                       }; 
 
        return products.Skip(startRowIndex).Take(maximumRows); 
    } 
 
    [WebMethod] 
    public static int GetProductCount() 
    { 
        var northwind = new NorthwindDataContext(); 
        var count = northwind.Products.Count(); 
        return count; 
    } 
     

Thanks in advance for taking the time to help me out.
D

2 Answers, 1 is accepted

Sort by
0
Accepted
BaiH
Top achievements
Rank 1
answered on 30 Jun 2009, 06:04 PM
Can you try declaring the webservice methods as instance methods instead of static, and see if this will  make any difference.

--BH
0
Darren
Top achievements
Rank 2
answered on 01 Jul 2009, 09:02 AM

Changed:
  • public static IEnumerable GetProducts(int startRowIndex, int maximumRows)
  • public static int GetProductCount()

To:
  • public IEnumerable GetProducts(int startRowIndex, int maximumRows)
  • public int GetProductCount() 

:-)
Tags
Grid
Asked by
Darren
Top achievements
Rank 2
Answers by
BaiH
Top achievements
Rank 1
Darren
Top achievements
Rank 2
Share this question
or