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 }