Is it possible to have a Gridview Section 508 compliant covering both point g & h?
Link for section 508 http://www.access-board.gov/sec508/guide/1194.22.htm Link for ASP.Net Section 508 Compliance http://www.patuee.com/web/ASPX_Accessibility.html#t7
After some research and googling I found the solution. I have written down below code and called it in RowDataBound event.
private void AddGridHeadersAttr(Object sender, GridViewRowEventArgs e, GridView Grid)
{
if (e.Row.RowType == DataControlRowType.Header)
{
for (int col = 0; col <= e.Row.Cells.Count - 1; col++)
{
e.Row.Cells[col].Attributes.Add("id", "ColumnHeader_" + Grid.Columns[col].HeaderText);
}
}
else if (e.Row.RowType == DataControlRowType.DataRow)
{
for (int col = 0; col <= e.Row.Cells.Count - 1; col++)
{
Object oCell = e.Row.Cells[col];
if (oCell is DataControlFieldHeaderCell)
{
((DataControlFieldHeaderCell)oCell).Attributes.Add("id", "RowHeader_" + Grid.Columns[col].HeaderText + e.Row.RowIndex.ToString());//Grid.DataKeys[e.Row.RowIndex].Value.ToString());
}
else
{
((DataControlFieldCell)oCell).Attributes.Add("headers", "ColumnHeader_" + Grid.Columns[col].HeaderText + " RowHeader_" + Grid.Columns[col].HeaderText + e.Row.RowIndex.ToString()); // Grid.DataKeys[e.Row.RowIndex].Value.ToString());
}
}
}
}
Hope this helps someone in future.