📄 default2.aspx.cs
字号:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using CrystalDecisions.CrystalReports.Engine;
public partial class Default2 : System.Web.UI.Page
{protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
FilLDropDownList();//填冲DropDownList控件
SqlConnection con = new SqlConnection("server=(local);uid=sa;pwd=;database=db_06");
con.Open();
string strSql = "select * from tb_worke";
SqlDataAdapter da = new SqlDataAdapter(strSql,con);
DataSet ds = new DataSet();
da.Fill(ds,"tb_worke");
con.Close();
ReportDocument studentsReport = new ReportDocument();//定义ReportDocument类对象
studentsReport.Load(Server.MapPath("CrystalReport.rpt"));//加载报表
studentsReport.SetDataSource(ds);//加载数据源
this.CrystalReportViewer1.ReportSource = studentsReport;//为CrystalReportViewer控件指定报表
}
}
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("server=(local);uid=sa;pwd=;database=db_06");
con.Open();
string strSql = "select * from tb_worke where 月份='" + DropDownList1.SelectedValue.ToString() + "'";
SqlDataAdapter da = new SqlDataAdapter(strSql, con);
DataSet ds = new DataSet();
da.Fill(ds, "tb_worke");
con.Close();
ReportDocument studentsReport = new ReportDocument();//定义ReportDocument类对象
studentsReport.Load(Server.MapPath("CrystalReport.rpt"));//加载报表
studentsReport.SetDataSource(ds);//加载数据源
this.CrystalReportViewer1.ReportSource = studentsReport;//为CrystalReportViewer控件指定报表
}
public void FilLDropDownList()//填冲DropDownList控件
{
SqlConnection con = new SqlConnection("server=(local);uid=sa;pwd=;database=db_06");
con.Open();
string strSql = "select distinct 月份 from tb_worke";
SqlCommand com = new SqlCommand(strSql, con);
SqlDataReader dr = com.ExecuteReader();
while (dr.Read())
{
DateTime dat = Convert.ToDateTime(dr[0].ToString());
DropDownList1.Items.Add(dat.ToShortDateString());
}
dr.Close();
con.Close();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -