I have paging enabled and I cannot export the entire data to excel
export button:
<img src="../images/i_exportXLS.png" /> <asp:Button ID="btnExport" runat="server" Text="Export to Excel" class="button" Width="140" OnClick="btnExport_Click" /> <ig:WebExcelExporter ID="exporter" runat="server" > </ig:WebExcelExporter>
paging:
<ig:Paging PageSize="100" Enabled="true" PagingClientEvents-PageIndexChanging="batchUpdateAlert" PagerAppearance="Both" > <PagingClientEvents PageIndexChanging ="batchUpdateAlert" /> </ig:Paging>
server side export function:
protected void btnExport_Click(object sender, EventArgs e) { try {
if (wdgModifyPositions.Rows.Count >= 1) { this.exporter.Export(this.wdgModifyPositions); lblError.Visible = false; AlertPic.Visible = false; } else { lblError.Text = "Please Load Data into the Data Grid"; lblError.Visible = true; AlertPic.Visible = true; } } catch (Exception ex) { ErrorHandle.ExceptionHelper(ex); } }
I saw the examples on forum for ultragrid :
UWGrid.DisplayLayout.Pager.AllowPaging = False
and this does not work on webdatagrid. What is possible way to disable paging on webdatagrid??
Thanks!!
Hello Jdag,
To get entire data to excel sheet while exporting the grid I would recommend instead of disable paging use DataExportMode property in the WebExcelExporter. DataExportMode determines whether the grid will export the entire set of data.
In the markup add the property as :
<ig:WebExcelExporter ID="WebExcelExporter11" DataExportMode ="AllDataInDataSource" runat="server" />
You can refer the following API link, list all the member exposed by exporter.
http://help.infragistics.com/doc/ASPNET/2015.2/CLR4.0/?page=Infragistics4.Web.v15.2~Infragistics.Web.UI.GridControls.BaseExporter_members.html
Please let me know if I may be further assistance.
Hi Divya,
Thank you I try to implement like that in future. For now I did following:
if (wdgModifyPositions.Rows.Count >= 1) { //disable paging before exporting this.wdgModifyPositions.Behaviors.Paging.Enabled= false; this.wdgModifyPositions.DataBind(); //export data this.exporter.Export(this.wdgModifyPositions); lblError.Visible = false; AlertPic.Visible = false; //enable paging this.wdgModifyPositions.Behaviors.Paging.Enabled = true; this.wdgModifyPositions.DataBind();}
I wanted to know how can I append date to download file name. Currently I am using downloadName
<ig:WebExcelExporter ID="exporter" runat="server" DownloadName="ModifyPositions" > </ig:WebExcelExporter>
I would like file name be like ModifyPositioons20161205.xls
I tried following but it does not work:
protected void btnExport_Click(object sender, EventArgs e) {
try {
if (wdgModifyPositions.Rows.Count >= 1) { //disable paging before exporting this.wdgModifyPositions.Behaviors.Paging.Enabled= false; this.wdgModifyPositions.DataBind(); //export data this.exporter.Export(this.wdgModifyPositions); lblError.Visible = false; AlertPic.Visible = false; //enable paging this.wdgModifyPositions.Behaviors.Paging.Enabled = true; this.wdgModifyPositions.DataBind();
string FileName = HttpUtility.UrlEncode("ModifyPositions" + DateTime.Now.ToString()); Response.Clear(); Response.AddHeader("content-disposition", "attachment; filename=" +FileName); Response.ContentType = "application/vnd.xls"; System.IO.StringWriter WriteItem = new System.IO.StringWriter(); System.Web.UI.HtmlTextWriter htmlText = new HtmlTextWriter(WriteItem); wdgModifyPositions.RenderControl(htmlText); Response.Write(WriteItem.ToString()); Response.End(); this.exporter.DownloadName = FileName;
else { lblError.Text = "Please Load Data into the Data Grid"; lblError.Visible = true; AlertPic.Visible = true; } } catch (Exception ex) { ErrorHandle.ExceptionHelper(ex); } }
To append date to download file name while exporting file in excel format, you have to append date in the file name and then replace “/” character as:
string fileName = "ModifyPositioons" + DateTime.Now.ToShortDateString();
fileName = fileName.Replace("/", "");
The reason this is happening is because the “/” character is not allowed to be in file names. So you have to convert it to something that is allowed. Note IE does this by default and converts the “/” to underscores “_”. Chrome doesn’t seem to do this and instead converts it to “%20”.
I have created a sample project find the attachment.
Please let me know if you have any further questions concerning this matter.
Dear Sirs, i have a similar problem but i can't solve with the DataExportMode as DataInGridOnly because i need to export from a filtered Datasource.
I try to explain better: in my page i'm using a WebHierarchicalDataGrid with Filtering and Paging Behaviors enabled, and (i think) that's the problem!
By now, It's impossibile to export all data when a customer use the filter for any column (and the data are in more than 1 page).
I can export each page by time.. but you can understand that's not a real solution.
I tryied also the Divya solution but i receive the Exception Thread.Ended:
Try WebHierarchicalDataGrid1.Behaviors.Paging.Enabled = False WebHierarchicalDataGrid1.DataBind() WebExcelExporter1.DownloadName = "ElencoMRP_Filtrato" WebExcelExporter1.DataExportMode = DataExportMode.DataInGridOnly 'DataExportMode.AllDataInDataSource WebExcelExporter1.Export(WebHierarchicalDataGrid1) WebHierarchicalDataGrid1.Behaviors.Paging.Enabled = True WebHierarchicalDataGrid1.DataBind() Catch ex As Exception Console.WriteLine(ex.Message) End Try
Could you please help me?
Thanks