Gridview adding row dynamically on RowDataBound with the same RowState (Alternate or Normal)

Posted by rob waminal on Stack Overflow See other posts from Stack Overflow or by rob waminal
Published on 2012-01-17T16:39:12Z Indexed on 2014/05/28 21:28 UTC
Read the original article Hit count: 194

Filed under:
|
|

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);
        }
    }
}

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about gridview