c# - Disable paging in GridView to Excel export -
i've got function export data gridview
excel, bound checkboxes. exports rows checked. works fine, can't seem disable paging export? code:
private void exportgridtoexcel() { bool isselected = false; foreach (gridviewrow in gridview1.rows) { checkbox cb = (checkbox)i.findcontrol("chkselect"); if (cb != null && cb.checked) { isselected = true; break; } } if (isselected) { gridview gvexport = gridview1; // below line not export checkbox excel file gvexport.columns[0].visible = false; foreach (gridviewrow in gridview1.rows) { gvexport.rows[i.rowindex].visible = false; checkbox cb = (checkbox)i.findcontrol("chkselect"); if (cb != null && cb.checked) { gvexport.rows[i.rowindex].visible = true; } } response.clear(); response.buffer = true; response.addheader("content-disposition", "attachment;filename=exportgriddata.xls"); response.charset = ""; response.contenttype = "application/vnd.ms-excel"; stringwriter sw = new stringwriter(); htmltextwriter htw = new htmltextwriter(sw); response.contentencoding = system.text.encoding.unicode; response.binarywrite(system.text.encoding.unicode.getpreamble()); response.cache.setcacheability(httpcacheability.nocache); gvexport.allowpaging = false; gvexport.rendercontrol(htw); response.output.write(sw.tostring()); response.end(); } } protected void button3_click(object sender, eventargs e) { exportgridtoexcel(); }
as can see i've set allowpaging = false
page numbers still visible in exported file. got idea why?
to export whole data gridview have re-bind datasource
//1.bind paging disabled gvexport.allowpaging = false; gvexport.databind(); //2.export method here //3.bind paging enabled gvexport.allowpaging = true; gvexport.databind();
but if it's possible export data directly datasource because have remove headers, hide columns, replace
, handle controls asp:checkbox
seperately
this approach if want export asop:gridview
- http://forums.asp.net/post/4222334.aspx
Comments
Post a Comment