简体   繁体   中英

unable to retain the values for dynamic creation of grid rows after print

i have a gridview in which i have created dynamic rows in row created event as shown in below code.

protected void grdPBook_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
      strPreviousRowID = DataBinder.Eval(e.Row.Date).ToString()}
      grdPBook.ShowFooter = false;
    }
}

protected void grdPBook_RowCreated(object sender, GridViewRowEventArgs e)
{
    bool IsSubTotalRowNeedToAdd = false;
    bool IsGrandTotalRowNeedtoAdd = false;

    if (ddlSummary.SelectedValue == "0")
    {
      if ((strPreviousRowID != string.Empty)(DataBinder.Eval(e.Row.DataItem,Date) != null))
      {
         if (strPreviousRowID != DataBinder.Eval(e.Row.DataItem, Date).ToString())
         {
            if (ddlSummary.SelectedValue == "0")
            {
               IsSubTotalRowNeedToAdd = true;
            }
         }
      }

      if (IsSubTotalRowNeedToAdd)
      {
         // ---code for adding dynamic subtotal row-----
      }
    }
}

when i print the grid the print dialog opens and after closing the dialog the dynamically generated columns of grid disappers and the grid gets messed up coz im not able to retain the values for Date(here)on the basis of which the dynamic rowsare generated.

How can i achieve the task.Help me.

protected void grdPBook_RowCreated(object sender, GridViewRowEventArgs e)
{
// your code
if (ddlSummary.SelectedValue == "0")
{
//your code
grdPBook.DataSource = dt;
//here dt is your Data Table object containing all rows.
}
grdPBook.DataBind();
}

Use grdPBook.DataBind(); in every Row operations.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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