我在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