set imageurl programatically

4 posts, 0 answers
  1. Patrick Lane
    Patrick Lane avatar
    17 posts
    Member since:
    May 2005

    Posted 25 Mar 2011 Link to this post

    How can I set imageurl for image column programatically?

    Thanks, Patrick
  2. Tsvetina
    Admin
    Tsvetina avatar
    1874 posts

    Posted 31 Mar 2011 Link to this post

    Hello Patrick,

    A possible approach would be:
    protected void RadTreeList1_ItemCreated(object sender, TreeListItemCreatedEventArgs e)
    {
        if (e.Item is TreeListDataItem)
        {
            ((e.Item as TreeListDataItem)["UniqueName"].Controls[0] as Image).ImageUrl = "imagePath";
        }
    }

    This way you will overcome the need of rebinding the treelist if you set this ImageUrl to the whole column in PreRender.

    Regards,
    Tsvetina
    the Telerik team
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Patrick Lane
    Patrick Lane avatar
    17 posts
    Member since:
    May 2005

    Posted 02 Apr 2011 Link to this post

    Hi tsvetina

    I didn't explain my requirement very well . What i'm trying to do is set a different the image in a column depending on the value of data in another column. For example, if value in column a is 100% then a green tick image in column b, if value in column a is below 50% then a red cross in column b. So I need to set the imageurl after itemdatabound event.

    Thanks Patrick
  5. Tsvetina
    Admin
    Tsvetina avatar
    1874 posts

    Posted 06 Apr 2011 Link to this post

    Hello Patrick,

    ItemDataBound is a possible place to set the ImageUrl as well, for example:

    protected void RadTreeList1_ItemDataBound(object sender, TreeListItemDataBoundEventArgs e)
    {
        if (e.Item is TreeListDataItem)
        {
            TreeListDataItem item = e.Item as TreeListDataItem;
            if (item["ColumnUniqueName"].Text == "Some value")
            {
                (item["ImagesColumn"].Controls[0] as Image).ImageUrl = "C1.png";
            }
            else
            {
                (item["ImagesColumn"].Controls[0] as Image).ImageUrl = "C2.png";
            }
        }
    }


    Regards,
    Tsvetina
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Back to Top