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

set imageurl programatically

3 Answers 90 Views
TreeList
This is a migrated thread and some comments may be shown as answers.
Patrick Lane
Top achievements
Rank 1
Patrick Lane asked on 26 Mar 2011, 02:34 AM
How can I set imageurl for image column programatically?

Thanks, Patrick

3 Answers, 1 is accepted

Sort by
0
Tsvetina
Telerik team
answered on 31 Mar 2011, 09:37 AM
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
0
Patrick Lane
Top achievements
Rank 1
answered on 02 Apr 2011, 06:47 AM
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
0
Tsvetina
Telerik team
answered on 06 Apr 2011, 02:40 PM
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
Tags
TreeList
Asked by
Patrick Lane
Top achievements
Rank 1
Answers by
Tsvetina
Telerik team
Patrick Lane
Top achievements
Rank 1
Share this question
or