Search code examples
c#asp.netgridviewobjectdatasource

Asp.net gridview rowupdated event e.Tow.RowType type?


I have some code in GridView1_RowDataBound event for html design of table :

if (e.Row.RowType == DataControlRowType.Header)
        {
            e.Row.TableSection = TableRowSection.TableHeader;

        }
        else if (e.Row.RowType == DataControlRowType.DataRow)
        {
            TableCellCollection cell = e.Row.Cells;
            cell[0].Attributes.Add("data-title", "");
            cell[1].Attributes.Add("data-title", "Product"  

        }

After row update I need do this again but I can't. Because RowUpdated EventArgs has no Row property. How can I solve this ?


Solution

  • You can loop the GridView rows outside the RowDataBound event also.

    foreach (GridViewRow row in GridView1.Rows)
    {
        TableCellCollection cell = row.Cells;
        cell[0].Attributes.Add("data-title", "");
        cell[1].Attributes.Add("data-title", "Product");
    }
    

    You can access the header row with this

    GridView1.HeaderRow.Cells[0].Attributes.Add("data-title", "");