符合Section 508标准的Gridview

时间:2012-05-07 11:27:25

标签: asp.net visual-studio-2008 section508 wcag

是否可以使Gridview Section 508兼容覆盖g& g; H +

第508条http://www.access-board.gov/sec508/guide/1194.22.htm的链接 ASP.Net Section 508合规性http://www.patuee.com/web/ASPX_Accessibility.html#t7

的链接

2 个答案:

答案 0 :(得分:1)

GridView的问题在于表格是自动生成的,因此转换为ListView可以省力;然后,您可以在ListView模板中以任何方式显示表标记。

为了让GridView执行此操作,您必须创建一个新的自定义控件GridView,该控件继承自开箱即用的控件。然后,您可以自定义新控件的表呈现输出。很多自定义GridViews的例子:)

根据Microsoft的说法,可以使用GridView完成辅助功能:

http://msdn.microsoft.com/en-us/library/ms228004.aspx#guideline_13__separating_structure_from_presentation

答案 1 :(得分:0)

经过一些研究和谷歌搜索后,我找到了解决方案。我在下面的代码中写下了并在RowDataBound事件中调用它。

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

希望这有助于将来。

相关问题