Good Day,
I am attempting to export the Web Hierarchical Data Grid to excel using the Web Excel Exporter control. My controls are currently sitting inside of an UpdatePanel control. I have set that to Conditional and set the "Export to Excel" button as a postback trigger. All is working well and it saves correctly. However, upon opening the file, all of the cells are empty in the excel worksheet.
This is my click event code (server side) for the excel export button, also, my grid is loaded dynamically from an ienumerable object:
protected void btnSchedule_ExportExcel_Click(object sender, EventArgs e)
{
LoadScheduleGrid();
this.weeSchedule.DownloadName = string.Format("HPDSchedule_{0}", DateTime.Now.ToString("MM-dd-yy(HHmm)"));
this.weeSchedule.ExportMode = ExportMode.Download;
this.weeSchedule.WorkbookFormat = Infragistics.Documents.Excel.WorkbookFormat.Excel97To2003;
this.weeSchedule.Export(this.whdgSchedule);
}
Hi jasonwilczak,
Thank you for posting in the community.
I have tested your scenario using an 11.2.20112.1019 WHDG bound to an IEnumerable datasource as described at:
http://blogs.infragistics.com/blogs/alex_kartavov/archive/2010/04/08/binding-webhierarchicaldatagrid-to-ienumerable.aspx
So far I am unable to replicate the scenario. A small sample illustrating the scenario would be greatly appreciated and will allow me to research the matter further. I would also require to know what version of .NetAdvantage you are using in your implementation.
Best Regards,
Petar IvanovDeveloper Support EngineerInfragistics, Inc.http://ko.infragistics.com/support
No problem, below i will be pasting three things, the first section will contain my objects that I am binding to the grid. There are two tiers, the top tier is the parent band and the second tier is the child band. The second thing i will post is my "LoadScheduleGrid" function which binds the object to the grid and the final section will be the actual grid in my .aspx page.
----------------SECTION 1
#region Daily - Internal
#region TopTier
public class ceDailyInternal_Bin
public string WorkGroup { get; set; }
//public string AssignmentName { get; set; }
public string ObjectType { get; set; }
public string Key { get; set; }
public string Tooltip { get; set; }
public string RosterDate { get; set; }
public string Data { get; set; }
public string OrgID { get; set; }
public string AttendanceData { get; set; }
public ceDailyInternal_Records Records { get; set; }
//public ceDailyInternal_Bin(DateTime cRosterDate, string cAssignmentName,string cWorkGroup,string cTooltip,string cData, string cOrgID)
public ceDailyInternal_Bin(DateTime cRosterDate, string cWorkGroup, string cTooltip, string cData, string cOrgID)
this.RosterDate = cRosterDate.Date.ToShortDateString();
//this.AssignmentName = cAssignmentName;
this.WorkGroup = cWorkGroup;
this.OrgID = cOrgID;
//this.Key = string.Format("{0}{1}{2}{3}", this.RosterDate, this.AssignmentName,this.WorkGroup,cOrgID);
this.Key = string.Format("{0}{1}",this.WorkGroup, cOrgID);
this.Tooltip = cTooltip;
this.ObjectType = "B";
this.Data = cData;
this.AttendanceData = "";
this.Records = new ceDailyInternal_Records();
public class ceDailyInternal_Bins : List<ceDailyInternal_Bin>
private EmployeeSvcRef.DailyRosterDCList _rawList;
public ceDailyInternal_Bins(EmployeeSvcRef.DailyRosterDCList cRawList)
_rawList = cRawList;
public ceDailyInternal_Bins SortByWorkgroup()
//this.Sort((x, y) => x.OrgID.CompareTo(y.OrgID));
ceDailyInternal_Bins _bins = new ceDailyInternal_Bins(this.RetrieveRawList());
//_bins.AddRange(this.OrderBy(x => x.OrgID).ThenBy(y => y.AssignmentName).ToList<ceDailyInternal_Bin>());
_bins.AddRange(this.OrderBy(x => x.WorkGroup).ToList<ceDailyInternal_Bin>());
return _bins;
public EmployeeSvcRef.DailyRosterDCList RetrieveRawList()
return _rawList;
#endregion
#region SecondTier
public class ceDailyInternal_Record
public string AssignmentName { get; set; }
public string Position { get; set; }
public string District { get; set; }
public string ShiftTime { get; set; }
public string EmployeeName { get; set; }
public string EmployeeNumber { get; set; }
public string JobType { get; set; }
public int RecordID { get; set; }
public string Color { get; set; }
public ceDailyInternal_Record(string cDistrict, DateTime cStartTime, DateTime cEndTime, int cRecordID, string cPosition,
string cEmployeeName, string cEmployeeNumber, string cTooltip, string cJobType, string cData, string cAssignmentName, string cAttendanceData, string cColor)
this.AssignmentName = cAssignmentName;
this.ShiftTime = string.Format("{0} - {1}", cStartTime.ToString("HHmm"), cEndTime.ToString("HHmm"));
this.RecordID = cRecordID;
this.Position = cPosition;
this.EmployeeName = cEmployeeName;
this.EmployeeNumber = cEmployeeNumber;
this.JobType = cJobType;
this.District = cDistrict;
this.ObjectType = "R";
this.AttendanceData = cAttendanceData;
this.Color = cColor;
public class ceDailyInternal_Records : List<ceDailyInternal_Record>
public ceDailyInternal_Records SortByAssignmentThenPositionThenShift()
ceDailyInternal_Records _recs = new ceDailyInternal_Records();
//_recs.AddRange(this.OrderBy(x => x.ShiftTime).ThenBy(y => y.Position).ToList<ceDailyInternal_Record>());
_recs.AddRange(this.OrderBy(x => x.AssignmentName).ThenBy(y => y.Position).ThenBy(z => z.ShiftTime).ToList<ceDailyInternal_Record>());
return _recs;
-----------------------------SECTION 2
private void LoadScheduleGrid()
ClientSessionDC _csdc = (ClientSessionDC)Session["ClientDC"];
this.whdgSchedule.GridView.ClearDataSource();
if (this.rbSchedule_DailyInternal.Checked)
this.btnSchedule_ToggleRows.Visible = true;
this.btnSchedule_ExportExcel.Visible = true;
this.btnSchedule_QuickPrint.Visible = false;
LoadwdmSchedule_Context(true);
SetSelectedFromDateToDateInSession(this.wdpSchedule_DailyDate.Date.Date, this.wdpSchedule_DailyDate.Date.Date);
SetTargetOrgID();
ceDailyInternal_Bins _bins = ceScheduleUtility.CreateDailyInternal(_csdc, null, null, GetFromDateInSession(),
GetToDateInSession(), GetTargetOrgID(), null, null,ASAP.Entity.PositionStatus.Scheduled);
this.whdgSchedule.DataSource = _bins;
SetInternalRawRosterList(_bins.RetrieveRawList());
///…unrelated code…//
//this.whdgSchedule.DataBind();
--------------------SECTION 3
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="left">
<ig:WebHierarchicalDataGrid ID="whdgSchedule" runat="server" Height="500px" Width="1400px" InitialDataBindDepth="-1" EnableDataViewState="True" AutoGenerateBands="true" AutoGenerateColumns="true" OnInitializeRow="whdgSchedule_InitializeRow" OnInitializeBand="whdgSchedule_InitializeBand" OnRowIslandDataBinding="whdgSchedule_RowIslandDataBinding">
<ClientEvents MouseDown="whdgSchedule_ContainerGrid_MouseDown" />
<Behaviors>
<ig:Selection RowSelectType="Single" CellClickAction="Row" Enabled="true" />
<ig:Activation Enabled="true"></ig:Activation>
<ig:EditingCore Enabled="true" EnableInheritance="true">
<ig:CellEditing Enabled="false" EnableInheritance="true">
</ig:CellEditing>
</Behaviors>
</ig:EditingCore>
</ig:WebHierarchicalDataGrid>
<ig:WebDataMenu ID="wdmSchedule_Context" runat="server" IsContextMenu="true" StyleSetName="Office2007Blue" BorderWidth="1">
<Items>
<ig:DataMenuItem Text="Detail Manpower" Key="detail" />
<ig:DataMenuItem Text="Take Attendance" Key="attendance" />
</Items>
<ClientEvents ItemClick="wdmSchedule_Context_ItemClick" />
</ig:WebDataMenu>
<ig:WebExcelExporter ID="weeSchedule" runat="server">
</ig:WebExcelExporter>
</td>
</tr>
</table>
Thank you for your reply.
After researching your code I believe the cause of your issues lies within the LoadScheduleInfo method. You are clearing the grid's datasource and afterwards assigning a datasource to the grid, however you also need to call DataBind() in order for the grid to be databound in time for exporting.
I would suggest that you either call DataBind() in the LoadSheduleInfo method or alternatively in the exporting method before calling Export() .
Please let me know if this helps.
Thank you, that was it. I called "DataBind()" method after the LoadScheduleGrid() method and before the export function and it all worked well. Quick question, the export to excel seems to have all the parent rows collapsed by default, how would I make it so all rows were expanded in the exported excel version?
In order to expand the rows in the exported documents you can call the following function after calling DataBind() on the grid:
protected void ExpandAll() { foreach (ContainerGridRecord row in WebHierarchicalDataGrid1.GridView.Rows) { row.ExpandChildren(); } }
protected void ExpandAll() { foreach (ContainerGridRecord row in WebHierarchicalDataGrid1.GridView.Rows) { row.ExpandChildren();
} }
Please tell me if this works.
Worked perfectly, thank you for all you're help!!
Glad that I was able to help. Please feel free to contact me if you need further assistance.
Thank you again, I have just posted a new issue in a different thread (didn't want to keep tacking on here) related to exporting to excel with multiple grids. http://community.infragistics.com/forums/p/63498/321607.aspx#321607