comment utiliser un composant d'une autre page
j'ai une page "WF_chrch_VT.aspx" qui contient une DropDownList, 3 TextBox, une GridView et une button .
voilà son code:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
| using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Text;
namespace WebApplication1
{
public partial class WF_chrchVT : System.Web.UI.Page
{
CrystalReport3 cr3 = new CrystalReport3();
protected void Page_Load(object sender, EventArgs e)
{
}
protected void DDLccrt_SelectedIndexChanged(object sender, EventArgs e)
{
SqlConnection cn = new SqlConnection();
cn.ConnectionString = "Data Source=amine;Initial Catalog=bdSPR;Integrated Security=True";
cn.Open();
SqlCommand com = new SqlCommand("select RibRip,DateVt,MntTotVt from Virement where NumVt='" +DDLccrt.SelectedValue + "'", cn);
SqlDataReader sdr = com.ExecuteReader();
if (sdr.Read())
{
TXTRibRip.Text = sdr[0].ToString();
TXTdatevt.Text = sdr[1].ToString();
TXTmnttot.Text = sdr[2].ToString();
Grd.Visible = true;
}
CrystalDecisions.CrystalReports.Engine.TextObject txt1;
txt1 = (CrystalDecisions.CrystalReports.Engine.TextObject)cr3.Section2.ReportObjects["Text9"];
txt1.Text = DDLccrt.Text;
}
protected void Button1_Click(object sender, EventArgs e)
{
Response.Redirect("CR_imprim.aspx");
}
}
} |
En faite lorsqu'on clique sur Button1 un CrystalReport doit étre affiché, le code source de cette page "CR_imprim.aspx" est le suivant:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
| using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Text;
namespace WebApplication1
{
public partial class CR_imprim : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
ReportDocument rptDoc = new ReportDocument();
DS ds = new DS(); // .xsd file name
DataTable dt = new DataTable();
// Just set the name of data table
dt.TableName = "Crystal Report Example";
dt = VtPc(); //This function is located below this function
ds.Tables[1].Merge(dt);
// Your .rpt file path will be below
rptDoc.Load(Server.MapPath("CrystalReport3.rpt"));
//set dataset to the report viewer.
rptDoc.SetDataSource(ds);
CrystalReportViewer1.ReportSource =rptDoc;
}
public DataTable VtPc()
{
//Connection string replcae 'databaseservername' with your db server name
string sqlCon = "Data Source=AMINE;Initial Catalog=bdSPR;Integrated Security=True";
SqlConnection Con = new SqlConnection(sqlCon);
SqlCommand cmd = new SqlCommand();
DataSet ds = null;
SqlDataAdapter adapter;
try
{
Con.Open();
//Stored procedure calling. It is already in sample db.
cmd.CommandText = "VtPc";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Connection = Con;
ds = new DataSet();
adapter = new SqlDataAdapter(cmd);
adapter.Fill(ds, "PieceComptable");
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
finally
{
cmd.Dispose();
if (Con.State != ConnectionState.Closed)
Con.Close();
}
return ds.Tables[0];
}
}
} |
mais le problème que je peux pas utiliser le composant "cr3" de "WF_chrch_VT.aspx" dans "CR_imprim.aspx" pour afficher
le TextBox! qu'est ce que je dois faire pour utiliser "cr3" au lieu de "rptDoc" comme ReportSource pour "CR_imprim.aspx":cry:
Merci d'avance