Alternate text for GridImageColumn

2 posts, 0 answers
  1. Christopher Bodnar
    Christopher Bodnar avatar
    7 posts
    Member since:
    Sep 2009

    Posted 24 Nov 2009 Link to this post

    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
  2. Roland
    Roland avatar
    156 posts
    Member since:
    Feb 2009

    Posted 24 Nov 2009 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top