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

Alternate text for GridImageColumn

1 Answer 195 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Christopher Bodnar
Top achievements
Rank 1
Christopher Bodnar asked on 24 Nov 2009, 01:37 PM
Hi,

I am using a GridImageColumn to display images.  However, I need data specific alternate text for each image for screen readers to pick up, like what the Tool Tip displays.  The AlternateText attibute is generic for the whole column and the DataAlternateTextField doesn't display if the images are missing.  Can anybody suggest a way to get data bound alternate text for this type of column.

Thank you,

Chris

1 Answer, 1 is accepted

Sort by
0
Roland
Top achievements
Rank 1
answered on 24 Nov 2009, 03:35 PM
Hello,

There is another way.

Instead of using GridImageColumn, you can use Templated Column
<telerik:GridTemplateColumn UniqueName="Column1" DataField="Field1"
                    <HeaderStyle Width="32px"></HeaderStyle> 
                    <ItemTemplate> 
                         <asp:Image id="myImg" runat="server"/> 
                    </ItemTemplate> 
 </telerik:GridTemplateColumn> 

Then

protected void grid_ItemDataBound(object sender, GridItemEventArgs e) 
        { 
 
            if (e.Item.ItemType != GridItemType.AlternatingItem && e.Item.ItemType != GridItemType.Item) 
            { 
                return
            } 
 
 var img = e.Item.FindControl("myImg"as Image; 
img.AlternateText = "my alternate text"
 
//or 
 
  var dataItem = e.Item.DataItem as MyDataBoundObject; 
 
img.AlternateText = dataItem.AltText; 

Assuming your grid is bound to collection of MyDataBoundObject and it has AltText property/field.
Tags
Grid
Asked by
Christopher Bodnar
Top achievements
Rank 1
Answers by
Roland
Top achievements
Rank 1
Share this question
or