【问题标题】:how to get gridview textbox value in crystal report in asp.net c#如何在asp.net c#中的水晶报表中获取gridview文本框值
【发布时间】:2012-07-19 02:51:36
【问题描述】:

我再次停留在 asp.net.. 我正在创建一个网站,人们在其中购买项目,从下拉列表中选择类别(在 sql server 故事名称中创建的数据库是项目,类别是它的字段)并显示到第一个 GridView 中。买家检查来自第一个 Gridview 的项目并单击选择按钮,这些选定的项目显示在第二个 Gridview 中。并且第二个 Gridview 有 TemplateField 文本框,它需要购买 Quantity 项目。

我想要的是当我点击生成报告时,gridview2 文本框的值应该在水晶报告中显示买方购买的数量。

我只需要这样做,我在报告中获取项目名称没有问题,但我无法获取 gridview 文本框的值。 我用谷歌搜索但没有运气....

任何人都可以帮助我举例说明..我正在研究 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();

}

谢谢

【问题讨论】:

    标签: asp.net gridview crystal-reports textbox


    【解决方案1】:

    我建议将所有(必要的)从“GridView”中选择的信息/数据保存到数据库,并将push 或pull 保存的数据保存到 CrystalReport 引擎。 p>

    您可以使用水晶报表参数来传递值或多个值,但根据您的需要,我不会帮助您。

    编辑:

    您正在尝试传递 TextBox 引用。请尝试以下操作:

      TextBox tx= GridView2.Rows[0].Cells[0].FindControl("TextBox1") as TextBox;
      rd.SetParameterValue("Quantity",tx.Text);
    

    对于多值(数组)参数值

      rd.SetParameterValue("@data", new int[]{10,20,30,40});
    

    【讨论】:

    • 感谢 AVD 的建议,我也尝试了 Crystalreport 参数。但它说“价值不在预期范围内。”
    猜你喜欢
    • 2017-09-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-24
    • 2010-09-25
    • 1970-01-01
    • 2015-06-11
    相关资源
    最近更新 更多