How to set image url if DataValue is null

2 posts, 0 answers
  1. sabarishbabu
    sabarishbabu avatar
    136 posts
    Member since:
    Apr 2009

    Posted 12 Sep 2009 Link to this post

    Hi,

    I have RadBinaryImage controls in DataBound column in RadGrid.

    I want to show a default  image if DataValue in Datasource is null.

    (ie.) I need to set ImageUrl if DataValue is null.

    Thans,
    Sabarish.
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 12 Sep 2009 Link to this post

    Hello Sabarish,

    Try out the following code to achieve the required:
    c#:
    protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
        { 
            if (e.Item is GridDataItem) 
            { 
                GridDataItem dataItem = (GridDataItem)e.Item; 
                if (((RadBinaryImage)dataItem["BinaryImageColumnUniqueName"].Controls[0]).ImageUrl == ""
                { ((RadBinaryImage)dataItem["BinaryImageColumnUniqueName"].Controls[0]).ImageUrl = "~/Images/Image1.gif"
                } 
            } 
       } 

    Thanks
    Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top