簡體   English   中英

將數據導出到Excel時,問題顯示為按鈕的錯誤

[英]problem to visible false of button when export data to excel

大家好我正在使用c#.net來制作web應用程序。 我正在制作一個將gridview數據導出為ex​​cel的網頁。 我的代碼如下

    protected void btnexport_Click(object sender, EventArgs e)
    {
        btnsubmit.Visible = false;
        exporttoexcel();
        expToExcel();
    }

    public override void VerifyRenderingInServerForm(Control control)
    {
        //base.VerifyRenderingInServerForm(control);
    }

    public void exporttoexcel()
    {
        Context.Response.Clear();

        Context.Response.AddHeader("content-disposition", "attachment;filename=FileName.xls");

        Context.Response.Charset = "";

        Context.Response.Cache.SetCacheability(HttpCacheability.NoCache);

        Context.Response.ContentType = "application/vnd.xls";

        System.IO.StringWriter stringWrite = new System.IO.StringWriter();

        System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);

        GridView1.RenderControl(htmlWrite);

        Context.Response.Write(stringWrite.ToString());

        Context.Response.End();

    }

我的gridview數據導出到excel成功,但在EXPORTTOEXCEL按鈕單擊事件我試圖虛假的另一個按鈕提交的可見屬性,但我成功這樣做所以請告訴我如何在EXPORTTOEXCEL按鈕單擊時將visible屬性設置為false事件

請盡快回復我的工作

我要提前感謝你們

您在回發時將按鈕可見性設置為false,但在同一請求中,您將清除響應並輸出Excel數據。 所以帶有隱形按鈕的控制樹永遠不會回到客戶端。

我猜你想要這樣做是為了在生成Excel時隱藏用戶的按鈕。 如果是這種情況,最好的辦法是使用客戶端javascript來隱藏按鈕。

您可以在按鈕的OnClientClick屬性中插入此javascript:

document.getElementById('<%=btnexport.ClientID%>').style.display = none;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM