0

i have a parent and a child GridView.
The Child gridview is populated by a value stored in parent DataSet Table.

child Gridview with Same Data

i need my Rows to fetch data according to the 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

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.

a little help would be highly appreciated, thanx in advance.


EDIT
Now i need to download a file which in present in child 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. child grid image

  • You are binding data to the GridView inside a `for` loop. So the nested gridview will always have the last dataset bound to it. – VDWWD Jul 27 '18 at 13:10

1 Answers1

0

When you RowDataBound you already have those row items that your are getting from getReportCode() method. All you have to do is read those items when you iterate using RowDataBound. In your cases, you can use below code to read 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.

dst = dm.ApprovalExpense("SelectForReport", reportCode, "", "", "", "", "", "");
GridView pubTitle = (GridView)e.Row.FindControl("GridView2");
Suprabhat Biswal
  • 3,033
  • 1
  • 21
  • 29
  • Welcome. If my answer solved your problem, click the big checkbox to accept it as the answer. This would help us (contributor) to build a repo. in this community. – Suprabhat Biswal Jul 28 '18 at 05:45
  • did that, if possible kindly help out with the edited part aswell. – Ashish Sharma Jul 28 '18 at 05:54
  • You can use LinkButton wrapped inside an Update Panel to perform a partial postback. In Code Behind use OnRowCommand to listen that event and here you can add download file logic. Also I would suggest you to create a new question rather editing in existing. This would attract other contributors to give you better suggestions or answers in your new post :) – Suprabhat Biswal Jul 28 '18 at 05:58