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. JavaScript
  4. Displaying data from database using javascript.

Displaying data from database using javascript.

Scheduled Pinned Locked Moved JavaScript
csharpjavascriptdatabasetoolstutorial
4 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.
  • M Offline
    M Offline
    miss786
    wrote on last edited by
    #1

    Hi, I would like the javascript to show data from getData method (webMethod), when the page loads but when filter the data (categoryPicker control), using webMethod getData2. This is currently my c# page.

    protected void Page_Load(object sender, EventArgs e)
    {
    if (!IsPostBack)
    {

            JavaScriptSerializer jss = new JavaScriptSerializer();
            ClientScript.RegisterStartupScript(this.GetType(), "TestInitPageScript",
                //string.Format("<script type=\\"text/javascript\\">google.load('visualization','1.0',{{'packages':\['corechart','controls'\]}});google.setOnLoadCallback(function(){'drawVisualization'({0},'{1}','{2}');});</script>",
           string.Format("<script type=\\"text/javascript\\">google.load('visualization','1.0',{{'packages':\['corechart','controls'\]}});google.setOnLoadCallback(function(){{drawVisualization({0},'{1}','{2}','{3}');}});</script>",
            jss.Serialize(GetData()),
        "Name Example",
        "Name",
        "Type Example",
        "Type Example",
         "Type,"));
    
        }
            else 
    
            {
                JavaScriptSerializer jtt = new JavaScriptSerializer();
        ClientScript.RegisterStartupScript(this.GetType(), "TestInitPageScript",
            //string.Format("<script type=\\"text/javascript\\">google.load('visualization','1.0',{{'packages':\['corechart','controls'\]}});google.setOnLoadCallback(function(){'drawVisualization'({0},'{1}','{2}');});</script>",
       string.Format("<script type=\\"text/javascript\\">google.load('visualization','1.0',{{'packages':\['corechart','controls'\]}});google.setOnLoadCallback(function(){{drawVisualization({0},'{1}','{2}','{3}');}});</script>",
        jtt.Serialize(GetData2()),
    "Name Example",
    "Name",
    "Type Example",
    "Type Example",
     "Type,"));
    
            }
        }
    
        
    
    
    
    \[WebMethod\]
    public static List GetData()
    {
        SqlConnection conn = new SqlConnection("#####");
        DataSet ds = new DataSet();
        DataTable dt = new DataTable();
        conn.Open();
        var yesterday = DateTime.Today.AddDays(-1);
        string cmdstr = "select top 500 Name, \[Decimal price\],Cover, UploadDate from \[dbo\].\[database\] order by UploadDate desc";
        SqlCommand cmd = new SqlCommand(cmdstr, conn);
        //cmd.Parameters.AddWithValue("@value", yesterday);
        SqlDataAdapter adp = new SqlDataAdapter(cmd);
        adp.Fill(ds);
    
    S 2 Replies Last reply
    0
    • M miss786

      Hi, I would like the javascript to show data from getData method (webMethod), when the page loads but when filter the data (categoryPicker control), using webMethod getData2. This is currently my c# page.

      protected void Page_Load(object sender, EventArgs e)
      {
      if (!IsPostBack)
      {

              JavaScriptSerializer jss = new JavaScriptSerializer();
              ClientScript.RegisterStartupScript(this.GetType(), "TestInitPageScript",
                  //string.Format("<script type=\\"text/javascript\\">google.load('visualization','1.0',{{'packages':\['corechart','controls'\]}});google.setOnLoadCallback(function(){'drawVisualization'({0},'{1}','{2}');});</script>",
             string.Format("<script type=\\"text/javascript\\">google.load('visualization','1.0',{{'packages':\['corechart','controls'\]}});google.setOnLoadCallback(function(){{drawVisualization({0},'{1}','{2}','{3}');}});</script>",
              jss.Serialize(GetData()),
          "Name Example",
          "Name",
          "Type Example",
          "Type Example",
           "Type,"));
      
          }
              else 
      
              {
                  JavaScriptSerializer jtt = new JavaScriptSerializer();
          ClientScript.RegisterStartupScript(this.GetType(), "TestInitPageScript",
              //string.Format("<script type=\\"text/javascript\\">google.load('visualization','1.0',{{'packages':\['corechart','controls'\]}});google.setOnLoadCallback(function(){'drawVisualization'({0},'{1}','{2}');});</script>",
         string.Format("<script type=\\"text/javascript\\">google.load('visualization','1.0',{{'packages':\['corechart','controls'\]}});google.setOnLoadCallback(function(){{drawVisualization({0},'{1}','{2}','{3}');}});</script>",
          jtt.Serialize(GetData2()),
      "Name Example",
      "Name",
      "Type Example",
      "Type Example",
       "Type,"));
      
              }
          }
      
          
      
      
      
      \[WebMethod\]
      public static List GetData()
      {
          SqlConnection conn = new SqlConnection("#####");
          DataSet ds = new DataSet();
          DataTable dt = new DataTable();
          conn.Open();
          var yesterday = DateTime.Today.AddDays(-1);
          string cmdstr = "select top 500 Name, \[Decimal price\],Cover, UploadDate from \[dbo\].\[database\] order by UploadDate desc";
          SqlCommand cmd = new SqlCommand(cmdstr, conn);
          //cmd.Parameters.AddWithValue("@value", yesterday);
          SqlDataAdapter adp = new SqlDataAdapter(cmd);
          adp.Fill(ds);
      
      S Offline
      S Offline
      Sunasara Imdadhusen
      wrote on last edited by
      #2

      Need more details inorder to understand your requirement. Can you please clarify little bit more in detail.

      1 Reply Last reply
      0
      • M miss786

        Hi, I would like the javascript to show data from getData method (webMethod), when the page loads but when filter the data (categoryPicker control), using webMethod getData2. This is currently my c# page.

        protected void Page_Load(object sender, EventArgs e)
        {
        if (!IsPostBack)
        {

                JavaScriptSerializer jss = new JavaScriptSerializer();
                ClientScript.RegisterStartupScript(this.GetType(), "TestInitPageScript",
                    //string.Format("<script type=\\"text/javascript\\">google.load('visualization','1.0',{{'packages':\['corechart','controls'\]}});google.setOnLoadCallback(function(){'drawVisualization'({0},'{1}','{2}');});</script>",
               string.Format("<script type=\\"text/javascript\\">google.load('visualization','1.0',{{'packages':\['corechart','controls'\]}});google.setOnLoadCallback(function(){{drawVisualization({0},'{1}','{2}','{3}');}});</script>",
                jss.Serialize(GetData()),
            "Name Example",
            "Name",
            "Type Example",
            "Type Example",
             "Type,"));
        
            }
                else 
        
                {
                    JavaScriptSerializer jtt = new JavaScriptSerializer();
            ClientScript.RegisterStartupScript(this.GetType(), "TestInitPageScript",
                //string.Format("<script type=\\"text/javascript\\">google.load('visualization','1.0',{{'packages':\['corechart','controls'\]}});google.setOnLoadCallback(function(){'drawVisualization'({0},'{1}','{2}');});</script>",
           string.Format("<script type=\\"text/javascript\\">google.load('visualization','1.0',{{'packages':\['corechart','controls'\]}});google.setOnLoadCallback(function(){{drawVisualization({0},'{1}','{2}','{3}');}});</script>",
            jtt.Serialize(GetData2()),
        "Name Example",
        "Name",
        "Type Example",
        "Type Example",
         "Type,"));
        
                }
            }
        
            
        
        
        
        \[WebMethod\]
        public static List GetData()
        {
            SqlConnection conn = new SqlConnection("#####");
            DataSet ds = new DataSet();
            DataTable dt = new DataTable();
            conn.Open();
            var yesterday = DateTime.Today.AddDays(-1);
            string cmdstr = "select top 500 Name, \[Decimal price\],Cover, UploadDate from \[dbo\].\[database\] order by UploadDate desc";
            SqlCommand cmd = new SqlCommand(cmdstr, conn);
            //cmd.Parameters.AddWithValue("@value", yesterday);
            SqlDataAdapter adp = new SqlDataAdapter(cmd);
            adp.Fill(ds);
        
        S Offline
        S Offline
        Sunasara Imdadhusen
        wrote on last edited by
        #3

        Need more details inorder to understand your requirement. Can you please clarify little bit more in detail.

        M 1 Reply Last reply
        0
        • S Sunasara Imdadhusen

          Need more details inorder to understand your requirement. Can you please clarify little bit more in detail.

          M Offline
          M Offline
          miss786
          wrote on last edited by
          #4

          Thank you for your response. I would like to be able to call (getData) query when the page loads and show the (getData) query results in a(using 'line method' -- see javascript code) line chart. When I use the data filters in javascript(categoryPicker), I would like to control filters (categoryPicker), to use (getData2) method query to filter the line charts' output. for example: when page loads, call query1(select top 100 * from data), then click/mouseover/search on filter(categoryPicker), filter the line chart results using qyery2(select * from data). I hope the explanation above clarifies my problem. Any help would be very much appreciated. Thank you for your time and help.

          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