简体   繁体   English

如何在asp.net C#中的水晶报表中获取GridView文本框值

[英]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保存的数据pushpull到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.

相关问题 如何在ASP.NET C#WebForm中的文本框和下拉列表的GridView页脚行中获取值 - How Can I get the value in the gridview footer row of textbox and dropdownlist in asp.net c# webform 如何在ASP.NET C#中的Crystal Report中发送多个参数值 - How to send multiple parameter value in crystal report in asp.net c# 尝试从C#(ASP.NET gridview)中的文本框获取文本值时出错 - Error while trying to get text value from textbox in C# (ASP.NET gridview) 如何在C#ASP.NET中从gridview的页脚行中找到文本框的值 - How to find the value of textbox from the footer row of gridview in C# ASP.NET 如何在asp.net C#中的焦点事件中从Gridview文本框中获取rowindex - how do get rowindex from Gridview Textbox in focus event in asp.net C# GridView中的DropDownList绑定到ASP.NET C#中GridView内TextBox中DropDown的选定值 - DropDownList in a GridView to bind the selected value of DropDown in TextBox inside a GridView in asp.net c# 如何在不询问参数字段的情况下在Asp.Net C#中的Crystal Report中加载子报表 - How to load sub report in Crystal Report in Asp.Net C# with out asking Parameter fields 在ASP.NET C#中直接打印Crystal报表 - Print Crystal Report Directly in ASP.NET C# 通过asp.net中的C#将参数传递给CRYSTAL REPORT - passing parameter to the CRYSTAL REPORT through C# in asp.net 将参数设置为Crystal报表ASP.net MVC c# - Setting Parameter To Crystal report ASP.net MVC c#
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM