[英]how to get gridview textbox value in crystal report in asp.net c#
i stuck again in asp.net.. i'm creating a website in which people purchases items selecting category(Database created in sql server tale name is items and category is its field) from dropdownlist and shows into a 1st GridView. 我再次停留在asp.net。 Buyer check the items from 1st Gridview and click select button and those selected items shows in 2nd Gridview.
买方检查第一个Gridview中的项目,然后单击选择按钮,这些选定的项目将显示在第二个Gridview中。 And 2nd Gridview has TemplateField Textbox and it take Quantity item purchased.
第二个Gridview具有TemplateField文本框,并且需要购买“数量”项。
What i want is when i click generate report the gridview2 textbox value should display Quantity purchased by buyer in crystal report. 我想要的是,当我单击生成报告时,gridview2文本框的值应在水晶报告中显示“买方购买的数量”。
i only need to do this only i have no problem getting item names in report but i can't get values of gridview textboxes. 我只需要这样做,就可以在报表中获取项目名称,但是我无法获取gridview文本框的值。 i Googled but no luck....
我用谷歌搜索,但没有运气。
anyone can help me with example please..i'm working on c# 任何人都可以帮我举个例子..我正在使用C#
I tried this 我试过了
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();
}
Thanks 谢谢
I'd suggest to save/persist all (necessary) selected information/data from "GridView" to the Database and push
or pull
saved data to the CrystalReport engine. 我建议将所有 (必要的)选定的信息/数据从“ GridView”保存/持久保存到数据库,然后
push
保存的数据push
或pull
到CrystalReport引擎。
You can use crystal report parameters to pass value or multiple values but as per your need I don't this would help you. 您可以使用Crystal Report 参数传递值或多个值,但是根据您的需要,我没有帮助。
Edit: 编辑:
You're trying to pass TextBox reference. 您正在尝试传递TextBox参考。 Try following:
请尝试以下操作:
TextBox tx= GridView2.Rows[0].Cells[0].FindControl("TextBox1") as TextBox;
rd.SetParameterValue("Quantity",tx.Text);
For multi-value (array) parameter value 对于多值(数组)参数值
rd.SetParameterValue("@data", new int[]{10,20,30,40});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.