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

RadGrid itemdatabound question

2 Answers 122 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mike2
Top achievements
Rank 1
Mike2 asked on 04 Aug 2010, 12:18 PM
I have a telerik:GridTemplateColumn in which I have placed an asp:image control (see code segment)
<telerik:GridTemplateColumn HeaderText="Status" UniqueName="TemplateColumn">
    <HeaderStyle Font-Bold="True" Font-Size="Medium" HorizontalAlign="Left" 
        VerticalAlign="Middle" Width="4%" />
        <ItemStyle Font-Size="Medium" HorizontalAlign="Center" 
            VerticalAlign="Middle"/>
            <ItemTemplate>
                <asp:Image ID="Image1" runat="server" 
                    ImageUrl="~/images/redlight.gif"/>
            </ItemTemplate>
</telerik:GridTemplateColumn>

I want to change the asp:image ImageUrl programatically in the ItemDataBound event.  The ItemDataBound GridItemEventArgs is "e".
I can access properties of this cell in a row as "e.item.cells[14]" and change its Backcolor: 
e.Item.Cells[14].BackColor = System.Drawing.Color.Red;

What syntax can I use to change the image url in this cell?

2 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 04 Aug 2010, 01:15 PM
Hello Mike,

In order to achieve this access the image and then change its url using ImageUrl property .

C#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
   {
       if (e.Item is GridDataItem)
       {
           GridDataItem item = (GridDataItem)e.Item;
           Image img = (Image)item.FindControl("Image1");
           img.ImageUrl = "~/Images/Update.gif"//set new url
       }
   }

Thanks,
Princy.
0
Mike2
Top achievements
Rank 1
answered on 09 Aug 2010, 04:01 PM
Yes, that was what I needed. Thanks.
Tags
Grid
Asked by
Mike2
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Mike2
Top achievements
Rank 1
Share this question
or