報表統計(十) 訪問資料庫 利用Ajax與資料控制項空間互動

來源:互聯網
上載者: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     }

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.