I send the Gridview as email body in asp.net using C#.

Everything works correctly, except that in the body of the email the Gridview is not formatted as expected, the style sheet CSS is not applied.

How to do resolve this ?

My code below, thanks in advance for any help.

markup code gridview

<asp:GridView ID="gvbody" AutoGenerateColumns="False" EmptyDataText="No data" 
    EnableViewState="true"
    runat="server" CssClass="mGrid" HorizontalAlign="Center" 
    OnRowDataBound="gvbody_RowDataBound">
    <AlternatingRowStyle CssClass="altrows" />
    <Columns>
        <asp:TemplateField HeaderText="N." 
         ItemStyle-CssClass="ddl_Class_new" ItemStyle-HorizontalAlign="Center">
            <ItemTemplate>
                <%#String.Format("{0:N0}",Container.DataItemIndex + 1)%>
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
</asp:GridView>

code-behind

public string GetGridviewData(GridView gv)
{
    StringBuilder strBuilder = new StringBuilder();
    StringWriter strWriter = new StringWriter(strBuilder);
    HtmlTextWriter htw = new HtmlTextWriter(strWriter);
    gv.RenderControl(htw);
    return strBuilder.ToString();
}


mailMessagePlainText.Body += GetGridviewData(gvbody);

Related posts

Recent Viewed