zoukankan      html  css  js  c++  java
  • 报表统计(十) 访问数据库 利用Ajax与数据控件空间交互

    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     }
    怀揣着一点点梦想的年轻人
    相信技术和创新的力量
    喜欢快速反应的工作节奏
  • 相关阅读:
    OpenGL ES 三种类型 uniform attribute varying
    Android显示YUV图像
    Android设置全屏
    Android 显示YUV编码格式
    关于Nexus 7的Usb host开发问题
    Android关闭系统锁屏
    java基础之Java变量命名规范
    java环境变量详解---找不到或无法加载主类
    PowerDesigner使用教程 —— 概念数据模型 (转)
    SQL Server高级内容之表表达式和复习
  • 原文地址:https://www.cnblogs.com/hfliyi/p/2730180.html
Copyright © 2011-2022 走看看