Functions in Grid.js not being called from WCF project

Last post 09-27-2010 3:13 PM by kuul13. 9 replies.
Page 1 of 1 (10 items)
Sort Posts: Previous Next
  • 09-22-2010 2:15 PM

    • kuul13
    • Top 200 Contributor
    • Joined on 09-20-2010
    • Wannabe Slacker
    • Points 54

    Functions in Grid.js not being called from WCF project

    I am using ajax.grid in my WCF solution that has GridControl, Service and WebClient projects. I have added the GridControl to my WebClient project but the functions in Grid.js is not being called. WebClient is a web application and I have added a WCF service (.svc) to it. Can you please guide me on where I could be going wrong? I verified that the ajax.controls.dll is there in the bin folder aswell. I don't get any error but nothing appears as the call to set_datasource doesn't run at all.

    I am calling a WCF service method to get all customer data. In set_dataSource() I ampassing arbitary name "customers". Here is my pageLoad code:
    function pageLoad(){

     

    var grid = $find("grid1");
    SriServiceLibrary.ISriService.GetAllCustomers(
          
    function(customers)
           {
                grid.set_dataSource(customers);
                grid.dataBind();
           } );
    }
    Though the code find's the grid control but doesn't do anything in set_dataSource function. I put aan alert in data.js file in that function but it doesn't call that function at all. I verified, GetAllCustomers method returns data. Is there any other way to verify if I any function in Grid.js is being called?

  •  Advertisement

    Featured Advertisement

     
  • 09-22-2010 2:19 PM In reply to

    • sonu
    • Top 10 Contributor
    • Joined on 05-22-2006
    • Montreal / Canada
    • Slacker
    • Points 12,183
    • MVP

    Re: Functions in Grid.js not being called from WCF project

    Can you try to use the latest version from codeplex?

    http://ajaxdatacontrols.codeplex.com/SourceControl/changeset/changes/52373

    [MVP since 2005] [MCAD]
    Webmaster of DotNetSlackers
    Question or Suggestion?
    Feel free to ask my any .NET question
    Our Posting FAQ
  • 09-22-2010 2:21 PM In reply to

    • sonu
    • Top 10 Contributor
    • Joined on 05-22-2006
    • Montreal / Canada
    • Slacker
    • Points 12,183
    • MVP

    Re: Functions in Grid.js not being called from WCF project

    Also what type is the customers object? Is it a datatable?

    [MVP since 2005] [MCAD]
    Webmaster of DotNetSlackers
    Question or Suggestion?
    Feel free to ask my any .NET question
    Our Posting FAQ
  • 09-23-2010 5:03 PM In reply to

    • kuul13
    • Top 200 Contributor
    • Joined on 09-20-2010
    • Wannabe Slacker
    • Points 54

    Re: Functions in Grid.js not being called from WCF project

    Thanks Sonu.. Was able to run it with the new DLL but still facing some issues.

    "Customer" is a Class object. And my service calls it very much like what is in the sample code. I am not sure if pagination works?

     


    total = 0;

     

    List<Customers> list = new List<Customers>();

     

    using (IDbConnection cnn = CreateConnection())
    {
     
    using (IDbCommand cmd = cnn.CreateCommand())
      {
        cmd.CommandText =
    string.Format(SQL, sortColumn, sortOrder, start, max);
        
    using (IDataReader rdr = cmd.ExecuteReader())
        {
         
    while (rdr.Read())
          {
           
    Customers c = BuildCustomer(rdr);
            list.Add(c);
          }
         
    if ((rdr.NextResult()) && (rdr.Read()))
          {
             total = rdr.GetInt32(0);
          } 
        }
      }
    }

     

    if ((list.Count == 0) || (total == 0))
    {
     
    return null;
    }

     

    PagedResult<Customers> result = new PagedResult<Customers>();
    result.Rows = list;
    result.Total = total;
    return result;

    total seems to always be 0. Am I missing something here?? I get a javascript error 'Tota' is null or not an object.

  • 09-23-2010 5:26 PM In reply to

    • sonu
    • Top 10 Contributor
    • Joined on 05-22-2006
    • Montreal / Canada
    • Slacker
    • Points 12,183
    • MVP

    Re: Functions in Grid.js not being called from WCF project

    Java script is case sensitive. So be sure to use count not Count. Its hard to tell what the problem is without seeing the relevant js code.

    [MVP since 2005] [MCAD]
    Webmaster of DotNetSlackers
    Question or Suggestion?
    Feel free to ask my any .NET question
    Our Posting FAQ
  • 09-24-2010 4:17 PM In reply to

    • kuul13
    • Top 200 Contributor
    • Joined on 09-20-2010
    • Wannabe Slacker
    • Points 54

    Re: Functions in Grid.js not being called from WCF project

     I verified, everything looks good in Javascript. Here is the js code: the error is in the following line:
    _pager.set_recordCount(result.Total);


    var _gridView;
    var _pager;
    function pageLoad(sender, e)
    {
    _gridView = GridView1;
    _pager = Pager1;
    loadCustomers();
    }

    function loadCustomers()
    {
    //Need to convert the sortoder so our WS understand
    var
    sortColumn = _gridView.get_sortColumn();
    var sortOrder = (_gridView.get_sortOrder() == AjaxDataControls.GridViewSortOrder.Descending) ? 'DESC' : 'ASC';
    var startIndex = (_pager.get_pageIndex() * _pager.get_pageSize());
    SriServiceLibrary.ISriService.GetCustomerList(startIndex, _pager.get_pageSize(), sortColumn, sortOrder, onLoadSuccess);
    }

    function onLoadSuccess(result)
    {
    _pager.set_recordCount(result.Total);
    _gridView.set_dataSource(result.Rows);
    _gridView.dataBind();
    }

    function onSortCommand(sender, e)
    {
    _gridView.set_sortColumn(e.get_sortColumn())
    _gridView.set_sortOrder(e.get_sortOrder());
    _pager.set_pageIndex(0);
    // need to reset the page index as sorting is changed
    loadCustomers();
    }

    function pageChanged(sender, e)
    {
    _pager.set_pageIndex(e.get_newPageIndex());
    loadCustomers();
    }

  • 09-24-2010 4:33 PM In reply to

    • sonu
    • Top 10 Contributor
    • Joined on 05-22-2006
    • Montreal / Canada
    • Slacker
    • Points 12,183
    • MVP

    Re: Functions in Grid.js not being called from WCF project

    The only advice I could give you is to run firebug in firefox and set the debugger in the onLoadSuccess function. Then simply debug the result object with firebug.

    function onLoadSuccess(result)
    {
        debugger;
        ....
    }

    [MVP since 2005] [MCAD]
    Webmaster of DotNetSlackers
    Question or Suggestion?
    Feel free to ask my any .NET question
    Our Posting FAQ
    Filed under: ,
  • 09-24-2010 4:49 PM In reply to

    • kuul13
    • Top 200 Contributor
    • Joined on 09-20-2010
    • Wannabe Slacker
    • Points 54

    Re: Functions in Grid.js not being called from WCF project

    I tried to debug through normal VS2008 and found that the webservice always return null. And I have used the same code that was there in your sample application. Only difference is that my database is MS Access and I am using WCF. But that should not make any difference. If you dry run your function GetProductList() you will see that the code will always return null as total is always 0. Appreciate if you can look at that method and let me know if I am missing something there?

  • 09-24-2010 4:55 PM In reply to

    • sonu
    • Top 10 Contributor
    • Joined on 05-22-2006
    • Montreal / Canada
    • Slacker
    • Points 12,183
    • MVP

    Re: Functions in Grid.js not being called from WCF project

    Why does it return null? There must be a problem with the connection to the access database. Can you see the values at all using VS debugger?

    [MVP since 2005] [MCAD]
    Webmaster of DotNetSlackers
    Question or Suggestion?
    Feel free to ask my any .NET question
    Our Posting FAQ
  • 09-27-2010 3:13 PM In reply to

    • kuul13
    • Top 200 Contributor
    • Joined on 09-20-2010
    • Wannabe Slacker
    • Points 54

    Re: Functions in Grid.js not being called from WCF project

     The database returns me the list of customers and it also adds it to the list. But I don't see any code that should increment total. If you can let me know what is this total? I may update the code myself. Do you know if the sample cod eis working for you?

Page 1 of 1 (10 items)