1

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);
        }
    }
}
rob waminal
  • 18,117
  • 17
  • 50
  • 64
  • So what is different? Is it in the wrong place? Is it appearing? – Dave Walker Jan 17 '12 at 16:58
  • no it's in the right place but as you can see the added row is a hidden row, and when the grid applies the alternating row, it will apply to the hidden row also.. I don't want to apply an alternating row to the added row. – rob waminal Jan 18 '12 at 06:32

1 Answers1

2

Ok the issue is that the GridView doesnt recognise display:none as meaning that this row will be hidden and so counts it as part of its alternating style. In this instance what you need to do is implement the styling explicitly yourself and remove it from the gridview definiton.

I will add a semi-example shortly have a meeting.

Dave Walker
  • 3,498
  • 1
  • 24
  • 25