Report statistics (10) access to the database using Ajax to interact with the data control space

Source: Internet
Author: User

View code

 1   Public   Partial   Class  Webform4: system. Web. UI. Page  2   {  3           Protected   Void Page_load ( Object  Sender, eventargs E)  4   { 5               If (! Ispostback)  6   {  7   Createchart ();  8 Bindgrid ( ""  );  9   }  10   }  11           Public Datatable getdata ( String  Strsql)  12   {  13 Sqlconnection con = New Sqlconnection ( "  Data Source =.; initial catalog = demo; Integrated Security = true  "  );  14 Sqlcommand cmd = New  Sqlcommand (strsql, con );  15 Sqldataadapter da = New  Sqldataadapter (CMD );  16 Dataset DS = New  Dataset ();  17   Da. Fill (DS );  18               Return DS. Tables [ 0  ];  19   }  20           Public  Void  Createchart ()  21   {  22               String Strsql = "  Select R. regionname, sum (S. Sales) as sumsales from regions R inner join reps_sales s on R. regionid = S. regionid group by R. regionname  "  ;  23 Datatable dt = Getdata (strsql );  24 Chart1.width =500  ;  25 Chart1.height = 300  ;  26 Chart1.series [ 0 ]. Tooltip = "  # Valx: \ t # Valy  "  ;  27 Chart1.datasource = DT;  28 Chart1.series [0 ]. Xvaluemember = "  Regionname  "  ;  29 Chart1.series [ 0 ]. Yvaluemembers = "  Sumsales  "  ;  30 Chart1.series [ 0 ]. Postbackvalue = "  # Valx "  ;  31   Chart1.databind ();  32   }  33   34           Public   Void Bindgrid ( String  Paramename)  35   {  36               If (Paramename =""  )  37   {  38 Paramename = "  Central  "  ;  39   }  40 Datatable dt = getdata ( String . Format ( " Select S. Name, S. Sales from regions R inner join reps_sales s on R. regionid = S. regionid where R. regionname = '{0 }'  "  , Paramename ));  41               This . Gv. datasource = DT;  42               This  . Gv. databind ();  43               This . Gv. Caption = Paramename;  44   } 45   46           Protected   Void Chart1_click ( Object  Sender, imagemapeventargs E)  47   {  48               String S = E. postbackvalue;  49   Bindgrid (s );  50   }  51 }

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.