我在asp.net中再次陷入了困境。我创建了一个网站,其中人们购买了选择类别的项目(数据库创建的sql服务器故事名称是项目和类别是它的字段)从下拉列表中显示并显示为第一个GridView。买方检查第一个Gridview中的项目并单击选择按钮,那些选定的项目显示在第二个Gridview中。第二个Gridview有TemplateField文本框,它会购买数量项目。如何在asp.net c#中的水晶报告中获取gridview文本框值#
我想要什么是当我点击生成报告gridview2文本框的值应该显示数量购买由水晶报告中的买方。
我只需要做到这一点,我没有问题在报表中获取项目名称,但我无法获取gridview文本框的值。 我一派,但没有运气....
任何人都可以帮助我的例子please..i'm C#的工作
我想这
protected void Button1_Click(object sender, EventArgs e)
{
List<string> checkedIDs = new List<string>();
for (int i = 0; i < GridView1.Rows.Count; i++)
{
CheckBox chbox = GridView1.Rows[i].Cells[0].FindControl("CheckBox1") as CheckBox;
if (chbox.Checked == true)
{
checkedIDs.Add("'" + GridView1.Rows[i].Cells[1].Text + "'");
}
}
string conn = ConfigurationManager.ConnectionStrings["Test_T3ConnectionString2"].ConnectionString;
SqlConnection con = new SqlConnection(conn);
string query = "select prod_name,price from products where prod_id in (" + string.Join(",", checkedIDs.ToArray()) + ")";
SqlCommand cmd = new SqlCommand(query, con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet1 ds = new DataSet1();
da.Fill(ds.Tables["Purchase_Report"]);
GridView2.DataSource = ds;
GridView2.DataBind();
ViewState["Records"] = ds;
}
protected void Button2_Click(object sender, EventArgs e)
{
ReportDocument rd = new ReportDocument();
rd.Load(Server.MapPath("CrystalReport.rpt"));
rd.SetDataSource(ViewState["Records"]);
rd.SetDatabaseLogon("sa", "abc", "localhost", "Test_T3");
rd.SetParameterValue("Quantity",GridView2.Rows[0].Cells[0].FindControl("TextBox1")); //this is what i tried, Quantity is a parameter i created in my crystal report
CrystalReportViewer1.ReportSource = rd;
CrystalReportViewer1.DataBind();
}
感谢
感谢提醒AVD我也尝试crystalreport参数的事情太多。但它说“价值不在预期范围内”。 – 2012-07-19 03:07:57
谢谢先生,它的工作原理! – 2012-07-19 03:24:21