如何在24小时后自动删除/隐藏gridview上的数据

时间:2021-02-02 09:13:59

I have a work that i display all of the bounced back email from EWS and i want to automatically remove or hide the data after 24 hours and display the new data. and here's my code to display the data

我有一项工作,我显示所有从EWS退回的电子邮件,我想在24小时后自动删除或隐藏数据并显示新数据。这是我显示数据的代码

public void LoadResult()
    {

        EmailMethods email = new EmailMethods();

        email.EmailServer = "https://SampleEWS.asmx";
        email.AccountName = ConfigurationManager.AppSettings["Account"];
        email.Password = ConfigurationManager.AppSettings["Secret"];
        email.Domain = ConfigurationManager.AppSettings["Domain"];
        email.GetEmails();
        DataTable dt = new DataTable();

        dt.Columns.Add("Subject", typeof(string));
        dt.Columns.Add("Sender", typeof(string));
        dt.Columns.Add("DateCreated", typeof(string));
        dt.Columns.Add("EmailHeader", typeof(string));
        dt.Columns.Add("ErrorTwo", typeof(string));



        foreach (Item item in email.EmailList)
        {
            dt.Rows.Add(item.Subject, item.DisplayTo, item.DateTimeCreated, item.Body, matchingMessage);

        }
        GridView1.DataSource = dt;
        GridView1.DataBind();

    }

the EmailMethods is my class that gets all of the undelivered/bounced back emails and here's my gidview code

EmailMethods是我的课程,可以获取所有未发送/退回的电子邮件,这是我的gidview代码

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" BackColor="White" BorderColor="#CC9966" BorderStyle="None" BorderWidth="1px" CellPadding="4" OnRowCommand="GridView1_RowCommand" Height="423px">
        <Columns>
            <asp:BoundField DataField="DateCreated" HeaderText="Date and Time" />
            <asp:BoundField DataField="ErrorTwo" HeaderText="Error" />
            <asp:TemplateField HeaderText="Receiver">
                <ItemTemplate>
                   <asp:LinkButton runat="server" CommandArgument='<%# Eval("Sender") %>' Text='<%# Eval("Sender") %>'></asp:LinkButton> <%--OnClientClick="document.getElementById('id01').style.display='block'; return false"--%>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:BoundField DataField="Subject" HeaderText="Email Error" />

            <asp:TemplateField HeaderText="Email Body">
                <ItemTemplate>
                   <asp:Button ID="txtItemBody"  runat="server" Text='<%# Eval("EmailHeader") %>' Width="100px" Enabled="false"/>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="View Email ">
                <ItemTemplate>
                   <asp:Button runat="server"  CommandName="Select" CommandArgument="<%# Container.DataItemIndex %>" Text="View Email" />
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
        <FooterStyle BackColor="#FFFFCC" ForeColor="#330099" />
        <HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="#FFFFCC" />
        <PagerStyle BackColor="#FFFFCC" ForeColor="#330099" HorizontalAlign="Center" />
        <RowStyle BackColor="whitesmoke" ForeColor="#0a0014" />
        <SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="#0a0014" />
        <SortedAscendingCellStyle BackColor="#FEFCEB" />
        <SortedAscendingHeaderStyle BackColor="#AF0101" />
        <SortedDescendingCellStyle BackColor="#F6F0C0" />
        <SortedDescendingHeaderStyle BackColor="#7E0000" />
    </asp:GridView>

and also i set this to refresh the page every 1 min

我也设置这个每1分钟刷新一次页面

<meta http-equiv="Refresh" content="60" />

can anyone help me or give some hints to fix my work thanks

任何人都可以帮助我或提供一些提示来解决我的工作,谢谢

1 个解决方案

#1


0  

Just wrap your dt.Rows.Add(...) method with the if condition to check if it's older than one day:

只需使用if条件包装dt.Rows.Add(...)方法,检查它是否超过一天:

if (item.DateTimeCreated > DateTime.Now.AddDays(-1.0))
{
    dt.Rows.Add(item.Subject, item.DisplayTo, item.DateTimeCreated, item.Body, matchingMessage);
}

#1


0  

Just wrap your dt.Rows.Add(...) method with the if condition to check if it's older than one day:

只需使用if条件包装dt.Rows.Add(...)方法,检查它是否超过一天:

if (item.DateTimeCreated > DateTime.Now.AddDays(-1.0))
{
    dt.Rows.Add(item.Subject, item.DisplayTo, item.DateTimeCreated, item.Body, matchingMessage);
}