Export only Gridview Data to Excel format in Asp.net C# -
in page have 2 textbox controls, gating date calendar extender & in export excel button going export gridview data excel sheet. when gating excel sheet show the textbox & button export excel sheet.
i have written export code in export button. like:-
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 header row white color grd_middata.headerrow.style.add("background-color", "#ffffff"); //applying stlye gridview header cells (int = 0; < 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) { } }
when gating excel sheet shows gridview data along 2 text box & button doing filtering.
so 1 suggest me, how show gridview data not show textbox & button on excel sheet.
you have bind data excel code, using below code
bindgriddata(); 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 ht = new htmltextwriter(sw); grd_middata.rendercontrol(ht); response.write(sw.tostring()); response.end();
it working me.
Comments
Post a Comment