I am getting a NullReferenceException when exporting my grid to Excel. It happens when I am referencing a button that exists in a GridTemplateColumn. I am setting the BackColor of the GridTableCell the button exists in and the CommandArgument of the button in the ItemDataBound event of the grid.
These are the lines I get the exception on.
((GridTableCell)btn.Parent).BackColor = System.Drawing.Color.Red;
btn.CommandArgument = "etid=" + drv["JOC_Event_Ticket_ID"] + "&ttype=" + drv["Ticket_Type_ID"];
Is there a way to get around this when exporting to Excel?
Thanks,
Steven
These are the lines I get the exception on.
((GridTableCell)btn.Parent).BackColor = System.Drawing.Color.Red;
btn.CommandArgument = "etid=" + drv["JOC_Event_Ticket_ID"] + "&ttype=" + drv["Ticket_Type_ID"];
Is there a way to get around this when exporting to Excel?
int
ticket_number =
int
.Parse(DataBinder.Eval(e.Item.DataItem,
"Ticket"
).ToString());
if
(Ticket_number > 0)
{
if
(ticket_number > 0)
{
e.Item.Cells[13].BackColor = System.Drawing.Color.Red;
((GridTableCell)btn.Parent).BackColor = System.Drawing.Color.Red;
}
if
(drv[
"JOC_Event_Ticket_ID"
].ToString().Length > 0)
{
btn.CommandArgument =
"etid="
+ drv[
"JOC_Event_Ticket_ID"
] +
"&ttype="
+ drv[
"Ticket_Type_ID"
];
}
else
{
btn.CommandArgument =
"problem_no="
+ drv[
"Ticket"
] +
"&ttype=1"
;
// +drv["Ticket_Type_ID"];
}
}
Thanks,
Steven