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 }
怀揣着一点点梦想的年轻人
相信技术和创新的力量
喜欢快速反应的工作节奏
相信技术和创新的力量
喜欢快速反应的工作节奏