I have webhierarchicaldata grid with two child grids. When I export the grid to excel using cellexporting event it always picks the alternate rows. Can anyone please suggest what is wrong in the code I am using:
if (!e.IsHeaderCell && !e.IsFooterCell ) { int index = GetIndex(System.Convert.ToString(e.Worksheet.Rows[0].Cells[e.CurrentColumnIndex].Value)); GridRecordItem item = WebHierarchicalDataGrid1.Rows[e.CurrentRowIndex - 1].Items[index]; if (item.Column.GetType().Name == "TemplateDataField") { TemplateDataField field = item.Column as TemplateDataField; HtmlAnchor proj_id = (HtmlAnchor)item.FindControl("demo"); if (proj_id != null) { e.WorksheetCell.Value = proj_id.Title; e.Cancel = true; } } else { e.WorksheetCell.Value = item.Text; e.Cancel = true; } }
Thanks,
Megha
Hello Megha,
Probably the logic in this method is wrong. Does GetIndex return the correct index?
Hi,
The code I have written always picks the alternate rows. Can you please provide me a sample code to iterate through all rows and columns of a webhierarchicaldatagrid.