This is a migrated thread and some comments may be shown as answers.

Setting scope attribute on GridTableCell?

6 Answers 255 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Scott
Top achievements
Rank 1
Scott asked on 30 Apr 2009, 04:52 PM
Hello,
I would like to add the scope attribute to a GridTableCell. I know this can be done for a GridTableHeaderCell. Essentially, what I want to be generated is:
<td scope="row">stuff</td>

for the leftmost table cell. In my BindColumnValues method I have tried the following:
GridDataItem dt = (GridDataItem)e.Item; 
GridTableHeaderCell rowHeader = (GridTableHeaderCell)dt["DocumentNumber"]; 
rowHeader.Scope = TableHeaderScope.Row; 
but, of course, this generates an exception ("Unable to cast object of type 'Telerik.Web.UI.GridTableCell' to type 'Telerik.Web.UI.GridTableHeaderCell'.")

Is there a way to do this? Am I missing something obvious?

Thanks,
Scott


6 Answers, 1 is accepted

Sort by
0
Accepted
Sebastian
Telerik team
answered on 05 May 2009, 01:40 PM
Hello Scott,

You can set the scope attribute for the grid items cells using the Attributes collection of the corresponding table cell. This operation can take place inside the ItemCreated server event handler of th grid, for example:

    protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)  
    {  
        if (e.Item is GridDataItem)  
        {  
            GridDataItem dataItem = e.Item as GridDataItem;  
            TableCell cell = dataItem["<MyColumnUniqueName"];  
            cell.Attributes["scope"] = "row";  
        }  
    } 

or from within your BindColumnValues method executed from the same handler. I hope this is applicable approach for your situation.

Best regards,

Sebastian
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Jeff
Top achievements
Rank 1
answered on 14 Jul 2009, 07:52 PM
Hello,

I have the same need. The solution provided almost works but has one major flaw- the cell is still a <td> not a <th>.

Here's what the output looks like:

<td scope="row"

I need:

<th scope="row"

Is there a way to tell RadGrid to change the type of tag to make my tables more 508 and search engine friendly?

Thanks,
Jeff





0
Sebastian
Telerik team
answered on 15 Jul 2009, 08:00 AM
Hello Jeff,

Changing the data rows in the grid to header rows cannot be supported because this will conflict with the rendering model of the control and its built-in features. I hope that you understand our position on this subject and the approach posted previously is feasible for you.

Best regards,
Sebastian
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Jeff
Top achievements
Rank 1
answered on 17 Jul 2009, 12:06 AM
I was reading the W3C standards and apparently <td scope="row"> is acceptable. So, that works for me.

Thanks,
Jeff


0
Ken Lassesen
Top achievements
Rank 2
answered on 19 Feb 2010, 02:11 AM
The following code can actually simplify the process for many. If marks all cells that are based on the DataKeyNames as scope="row". In general that is the 508 intent, to identify a unique combination of columns that qualifies the data. I have this in a utility library and just add it as needed (instead of copy and paste across hunderds of pages).

 

/// <summary>  
/// Routine to add scope="row" to the grid for 508 compliance. The items are those specified in  
/// DataKeyNames  
/// </summary>  
/// <param name="sender">a telerik radgrid control</param>  
/// <param name="e"></param>  
static void grid_ItemCreatedAddRowScope(object sender, GridItemEventArgs e)  
{  
    if (e.Item is GridDataItem)  
    {  
        GridDataItem dataItem = e.Item as GridDataItem;  
        foreach (string key in dataItem.OwnerTableView.DataKeyNames)  
        {  
            foreach (GridColumn col in dataItem.OwnerTableView.Columns)  
            {  
                if (col.IsBoundToFieldName(key))  
                {  
                    TableCell cell = dataItem[col.UniqueName];  
                    cell.Attributes["scope"] = "row";  
                }  
            }  
        }  
    }  

 

 

0
Jeff
Top achievements
Rank 1
answered on 19 Feb 2010, 04:54 PM
Thanks for the code, Ken. Very useful.
Tags
Grid
Asked by
Scott
Top achievements
Rank 1
Answers by
Sebastian
Telerik team
Jeff
Top achievements
Rank 1
Ken Lassesen
Top achievements
Rank 2
Share this question
or