您的位置:首页 > 数据库

报表统计(十) 访问数据库 利用Ajax与数据控件空间交互

2012-10-18 21:53 489 查看
View Code

public partial class WebForm4 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
CreateChart();
BindGrid("");
}
}
public DataTable GetData(string strSql)
{
SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=DEMO;Integrated Security=True");
SqlCommand cmd = new SqlCommand(strSql, con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
return ds.Tables[0];
}
public void CreateChart()
{
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";
DataTable dt = GetData(strSql);
Chart1.Width = 500;
Chart1.Height = 300;
Chart1.Series[0].ToolTip = "#VALX:\t#VALY";
Chart1.DataSource = dt;
Chart1.Series[0].XValueMember = "RegionName";
Chart1.Series[0].YValueMembers = "SumSales";
Chart1.Series[0].PostBackValue = "#VALX";
Chart1.DataBind();
}

public void BindGrid(string parameName)
{
if (parameName == "")
{
parameName = "Central";
}
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));
this.gv.DataSource = dt;
this.gv.DataBind();
this.gv.Caption = parameName;
}

protected void Chart1_Click(object sender, ImageMapEventArgs e)
{
string s = e.PostBackValue;
BindGrid(s);
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐