This is a migrated thread and some comments may be shown as answers.

e.Row.Cells.GetCellByName always returns null

4 Answers 154 Views
Grid
This is a migrated thread and some comments may be shown as answers.
CG
Top achievements
Rank 1
CG asked on 17 Aug 2011, 09:22 PM
Hello,

There is an issue with Radgrid excel exporting.

I have followed this example exactly http://demos.telerik.com/aspnet-ajax/grid/examples/generalfeatures/excelmlexport/defaultcs.aspx
except i make a call to the database on the code-behind rather than using a sqldatasource.

but on ExcelMLExportRowCreated i try to get a CellElement by cell name but it always comes back as null. i disabled autocreating columns because i create my own on the aspx page and i set a HeaderText, DataField, and UniqueName for each one. The datafield and UniqueName are the same and i use that when i call GetCellByName. Why is this not working?
What am i missing?

Please reply/fix asap.

Thanks.

4 Answers, 1 is accepted

Sort by
0
CG
Top achievements
Rank 1
answered on 17 Aug 2011, 09:34 PM
Nevermind this was solved. I forgot to add  UseAllDataFields="true"
but now i have another problem. After saving/opening the excel, the grid is locked in 'loading' phase...meaning it has the loading icon in front of the grid and everything is disabled.
How do i revert it back to a reusable grid?
0
Mira
Telerik team
answered on 23 Aug 2011, 08:51 AM
Hello Cg,

I am glad to hear the first issue is resolved.

To the second one: I tried to replicate it on the Export to ExcelML demo, but to no avail.
If the problem persists, please send us a small working project, demonstrating your full setup and showing the unwanted behavior.
We will debug it locally and get back to you.

Thank you in advance for the cooperation.

All the best,
Mira
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

0
Vijender Reddy
Top achievements
Rank 1
answered on 01 Nov 2013, 09:25 PM
hello,
    e.Row.Cells.GetCellByName inside ExcelMLExportRowCreated  is always null even after putting UseAllDataFields="true". I am using Needdatasource to bind the data through datatable. I have correct column but still gives me null for the cellElement. Please provide me quick reply

protected void btnExportExcel_Click(object sender, EventArgs e)

{

radGridSuspect.MasterTableView.Caption = AddComplainantandLeaInfo(chkComplainant.Checked, chkLeaInfo.Checked);

radGridSuspect.ExportSettings.FileName =

 

"Suspect";

radGridSuspect.ExportSettings.Excel.FileExtension =

 

 

 

 

 

"xls";

radGridSuspect.ExportSettings.ExportOnlyData =

 

 

 

 

 

true;

radGridSuspect.ExportSettings.IgnorePaging =

 

 

 

 

 

true;

radGridSuspect.ExportSettings.OpenInNewWindow =

 

 

 

 

 

true;

radGridSuspect.MasterTableView.ExportToExcel();

}

 

#endregion

 

 

 

 

 

 

 

protected void radGridSuspect_ExcelMLExportRowCreated(object source, GridExportExcelMLRowCreatedArgs e)

{

 

 

 

 

 

if (e.RowType == GridExportExcelMLRowType.DataRow)

{

 

 

 

 

 

foreach (GridColumn col in radGridSuspect.MasterTableView.Columns)

{

 

 

 

 

 

CellElement xlCell = e.Row.Cells.GetCellByName(col.UniqueName);

 

 

 

 

 

if (col.UniqueName == "FromCallDtm")

{

xlCell.StyleValue =

 

 

 

 

 

"InvoiceDateStyleValue";

}

}

}

 

 

 

 

 

// e.Row.Cells.GetCellByName("FromCallDtm").StyleValue = "InvoiceDateStyleValue";

}

 

 

 

 

 

protected void radGridSuspect_ExcelMLExportStylesCreated(object source, GridExportExcelMLStyleCreatedArgs e)

{

 

 

 

 

 

StyleElement InvoiceStyle = new StyleElement("InvoiceDateStyleValue");

InvoiceStyle.NumberFormat.FormatType =

 

 

 

 

 

NumberFormatType.ShortDate;

e.Styles.Add(InvoiceStyle);

}

 

protected void radGridSuspect_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)

{

 

this.radGridSuspect.DataSource = this.CaseTargetPhoneDataSuspect;

 

if (rbnSuspectShow.SelectedValue == "2")

{

 

try

{

 

GridGroupByExpression expression1 = GridGroupByExpression.Parse("SuspectName[Name],SuspectAddress1[Address1],SuspectAddress2[Address2],SuspectCity[City],SuspectStateCd[State],SuspectZip5[Zip] Group By SuspectPhoneNum Descending");

 

this.CustomizeExpression(expression1);

 

this.radGridSuspect.MasterTableView.GroupByExpressions.Add(expression1);

}

 

catch (Exception ex)

{

lblMessage.Text =

 

string.Format("<span style='color:red'>Cannot add group by expression: {0}</span>", ex.Message);

lblMessage.Visible =

 

true;

}

}

}

 

 



Thank you,
Vijender.
0
Kostadin
Telerik team
answered on 06 Nov 2013, 12:33 PM
Hello Vijender,

I have already answered your other forum thread, so I would suggest you to continue our conversation there and close this one.
Please note that opening multiple forum threads with the same issue makes tracking the forum threads history very hard. In this regard, I suggest you to stick to the first one. This will enable us to respond more quickly and efficiently to your posts.

Regards,
Kostadin
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
Tags
Grid
Asked by
CG
Top achievements
Rank 1
Answers by
CG
Top achievements
Rank 1
Mira
Telerik team
Vijender Reddy
Top achievements
Rank 1
Kostadin
Telerik team
Share this question
or