0

在我的页面上单击按钮时正在运行此代码:

protected void btnExportToPdfButton_click(object sender, EventArgs e)
{
    this.ProjectListGrid.ExportSettings.ExportOnlyData = true;
      this.ProjectListGrid.ExportSettings.Pdf.PageLeftMargin = Unit.Parse(".2in");
      this.ProjectListGrid.ExportSettings.Pdf.PageRightMargin = Unit.Parse(".2in");
    ApplyStylesToPdfExport(this.ProjectListGrid.MasterTableView);
    this.ProjectListGrid.MasterTableView.ExportToPdf();
}

public void ApplyStylesToPdfExport(GridTableView tableView)
{  
    // Get access to the header in the grid
    GridItem headerItem = tableView.GetItems(GridItemType.Header)[0];

    // Apply CSS Styles to the header
    headerItem.Style["font-size"] = "8pt";
    headerItem.Style["background-color"] = "#777";
    headerItem.Style["color"] = "white";

    // Apply CSS Styles to each cell in the header
    foreach (TableCell cell in headerItem.Cells)
    {
        cell.Style["color"] = "red";
    }
}

pdf 导出,根本没有应用自定义样式。我完全不知道我做错了什么。

4

1 回答 1

0

出于某种原因,控件似乎会重新绑定自身,因此它会清除您的内联样式。此行为的可能原因是您在标记中将 ExportSettings.IgnorePaging 设置为true。如果不是这种情况,并且您仍然遇到此问题,请在此处发布您的代码,以便我进行检查。

于 2012-02-27T10:32:18.133 回答