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

Get GridBinaryImageColumn to show nothing when NULL

2 Answers 77 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jon
Top achievements
Rank 1
Jon asked on 21 Jul 2009, 08:37 AM
Hi,

I use a binary image column in one of my grids.  Not every row will have an image - some will come as NULL from the database.  For those rows how do I stop the component trying to display the image?  I've looked through the fields for the column and can't see anything obvious so assume that I'll need to do something on the ItemDataBound event.  Has anyone encountered this yet and if so could you let me know how you resolved it?

What would be good is to be able to specify either an alternate image to display when there is no thumbnail or some text to display when no image.  Could that be built into a future version please?

Regards,

Jon

2 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 1
answered on 21 Jul 2009, 11:51 AM
Hello Jon,

Until Telerik provides a better solution, probably, you can work around this issue using the following code:
c#:
 protected void RadGrid_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e) 
    { 
        if (e.Item is GridDataItem) 
        { 
            GridDataItem dataItem = (GridDataItem)e.Item; 
            RadBinaryImage img = (RadBinaryImage)dataItem["BinaryImageColumnUniqueName"].Controls[0]; 
            if (img.ImageUrl == ""
            { 
                img.Visible = false
                LiteralControl literal = new LiteralControl(); 
                literal.Text = "No Image"
                dataItem["BinaryImageColumnUniqueName"].Controls.Add(literal); 
            }             
        }        
    } 

Thanks
Princy.
0
Jon
Top achievements
Rank 1
answered on 21 Jul 2009, 12:46 PM
Hi Princy,

Many thanks for that - I'd been trying to figure out what the name of the control would be within the column and didn't think of using the ordinal to get it!  Must get to bed earlier ;)

Thanks again,

Regards,

Jon
Tags
Grid
Asked by
Jon
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 1
Jon
Top achievements
Rank 1
Share this question
or