1

我正在使用RadGridwith Show Footer = true,当我在浏览器中打开此页面时,它工作正常。但是,当我通过电子邮件发送此网格并在 Outlook 中打开时,我的网格总数将显示在项目上方。请参阅下面与 Outlook 中的问题相关的屏幕截图

展望快照

它在浏览器(Firefox)中看起来不错。但是当我检查呈现的 HTML 时,页脚 HTML 位于页眉和正文之间。

我的示例代码:

<telerik:RadGrid ID="radGrid1" runat="server" OnItemDataBound="RadGrid1_ItemDataBound"
DataSourceID="ObjectDataSource1" OnDeleteCommand="radGrid1_OnDeleteCommand" OnItemCommand="RadGridTask_ItemCommand"
ShowFooter="true" AllowSorting="false">
<MasterTableView OverrideDataSourceControlSorting="true" CommandItemDisplay="None"
    NoDetailRecordsText="" NoMasterRecordsText="" EnableNoRecordsTemplate="false"
    ShowHeadersWhenNoRecords="false" EditMode="PopUp" DataKeyNames="LabourID" DataSourceID="ObjectDataSource1">
    <CommandItemSettings ExportToPdfText="Export to PDF" />
    <RowIndicatorColumn FilterControlAltText="Filter RowIndicator column" Visible="True">
    </RowIndicatorColumn>
    <ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column" Visible="True">
    </ExpandCollapseColumn>
    <Columns>



        <telerik:GridBoundColumn DataField="TotalMins" HeaderText="Duration" SortExpression="TotalMins"
            UniqueName="TotalMins" HeaderStyle-Width="90px" FilterControlAltText="Filter TotalMins column"
            Aggregate="Sum" FooterText=" ">
            <HeaderStyle BorderColor="#872B07" CssClass="tb_head" />
            <ItemStyle Wrap="false" Width="90px" CssClass="tb_cell" />
            <FooterStyle Font-Bold="True" Font-Size="12px"></FooterStyle>
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn DataField="TotalCharge" HeaderText="Total" SortExpression="TotalCharge"
            UniqueName="TotalCharge" DataFormatString="{0:c}" HeaderStyle-Width="80px" FilterControlAltText="Filter TotalCharge column"
            Aggregate="Sum" FooterText="Total: ">
            <HeaderStyle BorderColor="#872B07" CssClass="tb_head" />
            <FooterStyle Font-Bold="True" Font-Size="12px"></FooterStyle>
            <ItemStyle Wrap="false" Width="90px" CssClass="tb_cell" />
            <HeaderStyle Width="80px" />
        </telerik:GridBoundColumn>
    </Columns>
</MasterTableView>
<ClientSettings>
</ClientSettings>
<FilterMenu EnableImageSprites="False">
</FilterMenu>

4

2 回答 2

2

试试这个漂亮的小选项:

下面的代码片段显示了如何使用 Gmail 的 SMTP 服务器发送电子邮件:

public void SendMail(string smtpAddress, string from, string to, string body, string subject, bool isHtml, Stream attachmentStream, string fileName)
{
    SmtpClient smtpClient = new SmtpClient(smtpAddress);
    MailMessage email = new MailMessage();
    email.From = new MailAddress(from);
    email.To.Add(to);    
    email.Body = body;
    email.Subject = subject;
    email.IsBodyHtml = isHtml;
    smtpClient.EnableSsl = true;
    email.Attachments.Add(new Attachment(attachmentStream, fileName));

    NetworkCredential myCreds = new NetworkCredential("youremail@gmail.com", "yourpassword", "");
    smtpClient.Credentials = myCreds;

    smtpClient.Send(email);
}

请注意导出是如何“取消”的,但包含导出的“文件”的内存流作为附件添加到电子邮件中。取自这里

protected void RadGrid1_GridExporting(object source, GridExportingArgs e)
{
    if (e.ExportType == ExportType.Excel)
    {
        MemoryStream ms = new MemoryStream(new ASCIIEncoding().GetBytes(e.ExportOutput));
        SendMail("smtp.gmail.com", "sourcemail@gmail.com", "targetmail@gmail.com", "mail body", "mail subject", false, ms, "ExportedFile.xls");
    }
    Response.Redirect(Request.Url.AbsoluteUri);
}

或者,如果您只想获取 html 并将其发送到电子邮件中,请尝试以下操作:取自此处

<telerik:RadGrid ID="RadGrid1" Skin="Black" runat="server" GridLines="None" OnNeedDataSource="RadGrid1_NeedDataSource1">
    <MasterTableView>
        <Columns>
            <telerik:GridBoundColumn DataField="Subject" HeaderText="Subject">
            </telerik:GridBoundColumn>
        </Columns>
        <RowIndicatorColumn>
            <HeaderStyle Width="20px"></HeaderStyle>
        </RowIndicatorColumn>
        <ExpandCollapseColumn>
            <HeaderStyle Width="20px"></HeaderStyle>
        </ExpandCollapseColumn>
    </MasterTableView>
</telerik:RadGrid>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Send email - grid" />


protected void RadGrid1_NeedDataSource1(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
{
    List<MailMessage> mList = new List<MailMessage>();
    MailMessage m1 = new MailMessage();
    m1.Subject = "One";
    mList.Add(m1);
    MailMessage m2 = new MailMessage();
    m2.Subject = "Two";
    mList.Add(m2);
    MailMessage m3 = new MailMessage();
    m3.Subject = "Three";
    mList.Add(m3);
    RadGrid1.DataSource = mList;
}

protected void Button1_Click(object sender, EventArgs e)
{
    string GridRawHtml;
    StringWriter stringWriter = new StringWriter();
    HtmlTextWriter clearWriter = new HtmlTextWriter(stringWriter);
    RadGrid1.RegisterWithScriptManager = false;
    RadGrid1.RenderControl(clearWriter);
    GridRawHtml = clearWriter.InnerWriter.ToString();
    GridRawHtml = GridRawHtml.Remove(GridRawHtml.IndexOf("<script"), GridRawHtml.LastIndexOf("</script>") - GridRawHtml.IndexOf("<script"));
    Response.Write(GridRawHtml);
}
于 2013-10-07T14:09:41.027 回答
1

这很可能是因为 Telerik 的控件使用了很多 JavaScript 和嵌入式资源(= 很多 CSS)。正如@sine 在您问题的评论中所说,这些控件显然不是为电子邮件可传递性/可移植性而设计的。可能有一些 JS 管理网格的页脚位置,这些 JS 不会包含在 Outlook 邮件中(您应该在 Telerik 的论坛上提问以确保这一点)。

您应该考虑另一种以更“电子邮件”友好的格式生成网格的方法,因为这种 HTML 通常也带有可传递性/垃圾邮件检查问题。

于 2013-10-07T12:17:14.627 回答