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

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -