Gridview adding row dynamically on RowDataBound with the same RowState (Alternate or Normal)
- by rob waminal
I am adding rows dynamically on code behind depending on the Row currently bounded on RowDataBound event. I want that added row to be the same state (Alternate or Normal) of the currently bounded row is this possible?
I'm doing something like this but it doesn't follow what I want. I'm expecting the added row dynamically would be the same as the current row. But it is not.
protected void gv_RowDataBound(object sender, GridViewRowEventArgs e)
{
if(e.Row.RowType == DataControlRowType.DataRow)
{
GVData data = e.Row.DataItem as GVData; // not original object just for brevity
if(data.AddHiddenRow)
{
// the row state here should be the same as the current
GridViewRow tr = new GridViewRow(e.Row.RowIndex +1, e.Row.RowIndex + 1, DataControlRowType.DataRow, e.Row.RowState);
TableCell newTableCell = new TableCell();
newTableCell.Style.Add("display", "none");
tr.Cells.Add(newTableCell);
((Table)e.Row.Parent).Rows.Add(tr);
}
}
}