在我的頁面我有兩個文本框控件,我在日曆擴展程序中選擇日期擴展程序&的日期到excel按鈕我將導出Gridview數據到Excel表格。 當我選擇excel工作表時,顯示的文本框&也是我從中導出excel工作表的按鈕。在Asp.net中只導出Gridview數據到Excel格式C#
我已經在導出按鈕中寫入了導出代碼。 ,如: -
protected void Export_to_Excel_Click(object sender, EventArgs e)
{
try
{
Response.ClearContent();
Response.Buffer = true;
Response.AddHeader("content-disposition", string.Format("attachment; filename={0}", "Customers.xls"));
Response.ContentType = "application/ms-excel";
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
Grd_MidData.AllowPaging = false;
bindgriddata();
//Change the Header Row back to white color
Grd_MidData.HeaderRow.Style.Add("background-color", "#FFFFFF");
//Applying stlye to gridview header cells
for (int i = 0; i < Grd_MidData.HeaderRow.Cells.Count; i++)
{
Grd_MidData.HeaderRow.Cells[i].Style.Add("background-color", "#df5015");
}
Grd_MidData.RenderControl(htw);
Response.Write(sw.ToString());
Response.Flush();
}
catch (Exception ee)
{
}
}
當我選通excel表則顯示gridview的數據與兩個文本框&從那裏我做了過濾按鈕一起。
所以任何人都建議我,如何只顯示gridview數據,但不顯示excel工作表上的文本框&按鈕。
謝謝#Rajesh。我使用這個代碼。只有一個改變我做了,而不是Response.End();我已經使用Response.Flush();.但問題仍然存在。當我下載Excel表格時,它會顯示Gridview數據以及文本框和按鈕。就像我們打印屏幕一樣,它會顯示整頁數據......所以我怎樣才能從表格中刪除2個文本框和按鈕。 – Sabyasachi