Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Pass dataview to javascript [modified]

Pass dataview to javascript [modified]

Scheduled Pinned Locked Moved ASP.NET
javascriptdatabasetoolsquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Z Offline
    Z Offline
    zeeShan anSari
    wrote on last edited by
    #1

    hi all, this is code behind:

    [System.Web.Services.WebMethod, System.Web.Script.Services.ScriptMethod()]

    public static DataView getAccounts()
    {
        try
        {
            string strCon = ConfigurationManager.ConnectionStrings\["TFConnectionString"\].ToString();
            SqlDataSource db = new SqlDataSource();
            db.ConnectionString = strCon;
            db.SelectCommandType = SqlDataSourceCommandType.StoredProcedure;
            db.SelectCommand = "getAccounts";
            db.SelectParameters.Add("loginId", "K");
            DataSourceSelectArguments args = new DataSourceSelectArguments();
            DataView lst = (DataView)db.Select(DataSourceSelectArguments.Empty);
    
         
            return lst;
        }
        catch (Exception ex)
        {
            return null;
        }
    }
    

    and this is javascript:

    function f1()
    {

    PageMethods.getAccounts(callSuccess, callFailuer);

    }
    function callSuccess(result)
    {

    alert(result[0]["account_nick"]);

    }
    function callFailuer()
    {
    alert('Fail');
    }

    in codebehind lst [DataView] shows records but on javascript its call failuer methode why? i just want pass the data to javascript as a list. thanks

    modified on Thursday, August 13, 2009 12:33 PM

    A 1 Reply Last reply
    0
    • Z zeeShan anSari

      hi all, this is code behind:

      [System.Web.Services.WebMethod, System.Web.Script.Services.ScriptMethod()]

      public static DataView getAccounts()
      {
          try
          {
              string strCon = ConfigurationManager.ConnectionStrings\["TFConnectionString"\].ToString();
              SqlDataSource db = new SqlDataSource();
              db.ConnectionString = strCon;
              db.SelectCommandType = SqlDataSourceCommandType.StoredProcedure;
              db.SelectCommand = "getAccounts";
              db.SelectParameters.Add("loginId", "K");
              DataSourceSelectArguments args = new DataSourceSelectArguments();
              DataView lst = (DataView)db.Select(DataSourceSelectArguments.Empty);
      
           
              return lst;
          }
          catch (Exception ex)
          {
              return null;
          }
      }
      

      and this is javascript:

      function f1()
      {

      PageMethods.getAccounts(callSuccess, callFailuer);

      }
      function callSuccess(result)
      {

      alert(result[0]["account_nick"]);

      }
      function callFailuer()
      {
      alert('Fail');
      }

      in codebehind lst [DataView] shows records but on javascript its call failuer methode why? i just want pass the data to javascript as a list. thanks

      modified on Thursday, August 13, 2009 12:33 PM

      A Offline
      A Offline
      Abhishek Sur
      wrote on last edited by
      #2

      DataView is not serialized. You need to pass XML or JSON serialized data objects through return. Rather than going like this, I recommend to use a comma separated string to pass data to the javascript function.:thumbsup::thumbsup:

      Abhishek Sur


      My Latest Articles **Create CLR objects in SQL Server 2005 C# Uncommon Keywords Read/Write Excel using OleDB

      **Don't forget to click "Good Answer" if you like to.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups