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

GridImageColumn dependent on datafield?

2 Answers 54 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ahrensberg
Top achievements
Rank 1
Ahrensberg asked on 24 Sep 2009, 02:47 PM
Hi all,

I have a grid in which I in the first column want to show either a red or a green bullet depending on what a datafield called "Status" contains (true/false). How can I do that?

Best regards...

2 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 1
answered on 25 Sep 2009, 04:10 AM
Hello Ahrensberg,

You can check out the following code sample which should probably help you achieve the required:
aspx:
 <telerik:GridTemplateColumn> 
      <ItemTemplate> 
           <asp:Image ID="Image1" runat="server" /> 
      </ItemTemplate> 
 </telerik:GridTemplateColumn> 
                     
 <telerik:GridBoundColumn DataField="Status" HeaderText="Status" UniqueName="Status">                       
 </telerik:GridBoundColumn>  

c#:
 protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e) 
    { 
        if (e.Item is GridDataItem) 
        { 
            GridDataItem item = (GridDataItem)e.Item; 
            Image img = (Image)item.FindControl("Image1"); 
            if (item["Status"].Text == "true"
            {                 
                img.ImageUrl = "~/Images/Image1.gif"
            } 
            else 
            { 
                img.ImageUrl = "~/Images/Image2.gif"
            } 
        } 
    } 

Thanks
Princy.
0
Ahrensberg
Top achievements
Rank 1
answered on 28 Sep 2009, 08:07 AM
Thank you! :)
Tags
Grid
Asked by
Ahrensberg
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 1
Ahrensberg
Top achievements
Rank 1
Share this question
or