更新面板方法未触发

本文关键字:方法 更新 | 更新日期: 2023-09-27 18:34:16

UpdatePanel内,我试图绑定到ListView并将其内容导出到 Excel。 这些功能独立工作正常(我的"运行报告"按钮绑定ListView,"导出到 Excel"按钮使用 EPPlus 导出.xlsx文件)。 为了使.xlsx导出正常工作,我必须为"导出到Excel"按钮创建一个<Triggers> Postback

我希望"导出到 Excel"按钮既绑定ListView又导出.xlsx。我已经添加了将ListView绑定到导出方法中的方法,但它似乎跳过了它。 我想我不理解回发的某些部分。

这是<Trigger>

<Triggers>
    <asp:PostBackTrigger ControlID="export" />
</Triggers>

以下是ListView绑定:

public void runreport(object sender, EventArgs e)
{
    reportlv.DataSource = null;
    reportlv.DataBind();
    bindreportlv();
    elreportdiv.Visible = true;
}

下面是嵌入了运行报告方法的导出方法:

protected void export_Click(object sender, EventArgs e)
{
    runreport(null, null);
    ExcelPackage pck = new ExcelPackage();
    ExcelWorksheet ws = pck.Workbook.Worksheets.Add("worksheet");
    DataTable dt = new DataTable();
    dt.Columns.Add(new DataColumn("Date", typeof(string)));
    dt.Columns.Add(new DataColumn("Payee", typeof(string)));
    dt.Columns.Add(new DataColumn("Amount", typeof(string)));
    foreach (ListViewDataItem li in reportlv.Items)
    {
        if (li.ItemType == ListViewItemType.DataItem)
        {
            DataRow dr = dt.NewRow();
            dr["Date"] = ((Label)li.FindControl("lbldate")).Text.ToString();
            dr["Payee"] = ((Label)li.FindControl("lblpayee")).Text.ToString();
            dr["Amount"] = ((Label)li.FindControl("lblamt")).Text.ToString();
            dt.Rows.Add(dr);
        }
    }
    ws.Cells["A1"].LoadFromDataTable(dt, true);
    pck.SaveAs(Response.OutputStream);
    Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
    Response.AddHeader("content-disposition", "attachment;  filename=summary.xlsx");
    Response.Flush();
    Response.End();
}

以下是按钮:

<asp:Button runat="server" ID="run" OnClick="runreport" CssClass="button" Text="Run Report" />
<asp:Button runat="server" ID="export" OnClick="export_Click" CssClass="button" Text="Export to Excel" />

更新

这是Page_Load方法:

protected void Page_Load(object sender, EventArgs e)
{
    if (IsPostBack)
    {
        runreport(null, null);
    }
}

更新面板方法未触发

<Triggers> <asp:PostBackTrigger ControlID="export" onclick ="CLick" /> </Triggers>