Exporting with styling

4 posts, 0 answers
  1. Tina
    Tina avatar
    130 posts
    Member since:
    Jul 2011

    Posted 19 Apr 2012 Link to this post

    Is itpossible to set row(alternating) color for exported document like we set in radgrid.I am using built in export button for exporting.
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 20 Apr 2012 Link to this post

    Hi Tina,

    Try the following code snippet to set color for alternating rows in the exported document.

    C#:
    protected void radgrid1_ExportCellFormatting(object sender, ExportCellFormattingEventArgs e)
        {
            GridDataItem item = e.Cell.Parent as GridDataItem;
            if (item.ItemType == GridItemType.AlternatingItem)
            {
                item.Style["background-color"] = "Red";
            }
            else
            {
                item.Style["background-color"] = "Blue";
            }
        }

    Thanks,
    Princy.
  3. Tina
    Tina avatar
    130 posts
    Member since:
    Jul 2011

    Posted 22 Apr 2012 Link to this post

    Thanks,
    It worked.One more question.I have a column which is a date field which is alignd right by default when exporteed.Is that possible to change the alignment of the column?
  4. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 23 Apr 2012 Link to this post

    Hello Tina,

    Try the following code to align the text when exported.
    C#:
    protected void RadGrid1_ExportCellFormatting(object sender, ExportCellFormattingEventArgs e)
    {
     if (e.FormattedColumn.UniqueName == "UniqueName")
     {
      e.Cell.Style["text-align"] = "center";
     }
    }

    Thanks,
    Princy.
Back to Top