简体   繁体   English

嵌套的Gridview在每行DataBound上显示相同的数据并在子Gridview中下载文件

[英]Nested Gridview Showing Same Data on every row DataBound & downloading a file within Child Gridview

i have a parent and a child GridView. 我有一个父母和一个孩子GridView。
The Child gridview is populated by a value stored in parent DataSet Table. Child网格视图由存储在父DataSet表中的值填充。

child Gridview with Same Data 具有相同数据的子Gridview

i need my Rows to fetch data according to the ReportCode. 我需要我的行根据ReportCode获取数据。

Here is my code:- 这是我的代码:

protected void GridView1_OnRowDataBound(object sender, GridViewRowEventArgs e)
    {
        try
        {
            DataSet dstReportsCodes = getReportCode();
            dst = new DataSet();
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                string pub_id = GridView1.DataKeys[e.Row.RowIndex].Value.ToString();
                dm.Open();
                //dst = dm.ApprovalExpense("SelectForReport", "Exp-4OWTR", "", "", "", "", "", "");    // which are the expenses
                if (dstReportsCodes.Tables[0].Rows.Count > 0)
                {
                    for (int i = 0; i < dstReportsCodes.Tables[0].Rows.Count; i++)
                    {
                        dst = null;
                        dst = dm.ApprovalExpense("SelectForReport", Convert.ToString(dstReportsCodes.Tables[0].Rows[i]["ReportCode"]), "", "", "", "", "", "");
                        GridView pubTitle = (GridView)e.Row.FindControl("GridView2");
                        pubTitle.DataSource = dst.Tables[0];
                        pubTitle.DataBind();
                    }
                }

                dm.Close();
            }
        }
        catch (Exception ex) { lblErrorText.Text = ex.ToString(); }
    }

NOTE : getReportCode() is the function which is returning a dataset with Report Codes, the ReportCode is fetched like Report Code Image 注意:getReportCode()是返回带有报告代码的数据集的函数,该报告代码的获取方式类似于报告代码图像

Now these report codes are used to fetch data for every row of Child Gridview, the details are coming in OK but it is binding same data everytime. 现在,这些报告代码用于获取Child Gridview的每一行的数据,详细信息确定,但是每次都绑定相同的数据。

a little help would be highly appreciated, thanx in advance. 提前感谢thanx的帮助。


EDIT 编辑
Now i need to download a file which in present in child gridview. 现在,我需要下载一个文件,该文件当前存在于子gridview中。
what is the best possible way to do that/ 做到这一点的最佳方法是什么/
what argument should i pass ? 我应该通过什么论点? (like its address or what?) (例如其地址或什么?)
i need the file to be downloaded without the child gridview being collapsed. 我需要在不折叠子gridview的情况下下载文件。 child grid image 子网格图像

When you RowDataBound you already have those row items that your are getting from getReportCode() method. 当您使用RowDataBound时,已经具有从getReportCode()方法获取的那些行项目。 All you have to do is read those items when you iterate using RowDataBound. 您要做的就是在使用RowDataBound进行迭代时阅读这些项目。 In your cases, you can use below code to read ReportCode. 在您的情况下,您可以使用以下代码读取ReportCode。

string reportCode = Convert.ToString(DataBinder.Eval(e.Row.DataItem, "ReportCode"));

Next, All you have to do is pass reportCode as parameter in your ApprovalExpense method. 接下来,您要做的就是将ReportCode作为参数传递给您的ApprovalExpense方法。

dst = dm.ApprovalExpense("SelectForReport", reportCode, "", "", "", "", "", "");
GridView pubTitle = (GridView)e.Row.FindControl("GridView2");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM