crystal reports using parameters
i am using crystal reports for the first time. I have written code which is as follows
public partial class _Default : System.Web.UI.Page
{
private ReportDocument report = new ReportDocument();
protected void Page_Load(object sender, EventArgs e)
{
report.Load(Server.MapPath("CrystalReport1.rpt"));
report.FileName = Server.MapPath("CrystalReport1.rpt");
if (!Page.IsPostBack)
{
BindData();
}
}
protected override void OnUnload(EventArgs e)
{
base.OnUnload(e);
this.Unload+=new EventHandler(Page_Unload);
}
public void Page_Unload(object sender, EventArgs e)
{
report.Clone();
report.Dispose();
}
private void BindData()
{
Trusted_Connection=true";
string connectionString = @"Data Source=WINSERVER;Initial Catalog=card;User ID=sa;Password = db2admin";
SqlConnection myConnection = new SqlConnection(connectionString);
SqlDataAdapter ad = new SqlDataAdapter("SELECT name,address,idno FROM iffcar", myConnection);
DataSet ds = new DataSet();
ad.Fill(ds);
DropDownList1.DataSource = ds;
DropDownList1.DataTextField = "name";
DropDownList1.DataValueField = "idno";
DropDownList1.DataBind();
}
protected void Btn_DisplayReport(object sender, EventArgs e)
{
int idno = Convert.ToInt32(DropDownList1.SelectedValue);
report.SetParameterValue("idno", idno);
CrystalReportViewer1.ReportSource = report;
}
}
i am getting values in the dropdownlist but,
Now my problem is onc开发者_如何转开发e i select a value from dropdownlist i want report of that value. how to do it.....
please help me to solve my problem.
Try using the index number of the parameter:
protected void Btn_DisplayReport(object sender, EventArgs e)
{
int idno = Convert.ToInt32(DropDownList1.SelectedValue);
report.SetParameterValue(0, idno);
CrystalReportViewer1.ReportSource = report;
}
精彩评论