How come this doesn't work for getting the text value of a literalcontrol on export of a gridview to Excel?
cell.Text = (cell.Controls[0] as LiteralControl).Text;
Edit: (Complete Code)
if (cell.HasControls())
{
switch (cell.Controls[0].GetType().Name)
{
case "HyperLink":
cell.Text = (cell.Controls[0] as HyperLink).Text;
cell.Controls.Clear();
cell.ForeColor = System.Drawing.ColorTranslator.FromHtml("#000000");
break;
case "LinkButton":
cell.Text = (cell.Controls[0] as LinkButton).Text;
cell.Controls.Clear();
cell.ForeColor = System.Drawing.ColorTranslator.FromHtml("#000000");
break;
case "LiteralControl":
cell.Text = (cell.Controls[0] as LiteralControl).Text;
cell.Controls.Clear();
cell.ForeColor = System.Drawing.ColorTranslator.FromHtml("#000000");
break;
}
//cell.Text = cell.Controls[0].GetType().Name;
}