Section 508 compliant Gridview
-
06-06-2021 - |
質問
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
解決 2
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.
他のヒント
The problem with GridView is that the tables are auto-generated, so a conversion to ListView would pay off effort-wise; you could then display table markup any way you want in ListView templates.
In order to get the GridView to do this, you would have to create a new custom control GridView which inherits from the out-of-the-box one. Then you could customize the table rendering output of the new control. Many examples of custom GridViews out there :)
According to Microsoft, accessibility can be accomplished with the GridView: