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

[Solved] Image in the background of the cell

7 Answers 141 Views
Grid
This is a migrated thread and some comments may be shown as answers.
tcipcic
Top achievements
Rank 1
tcipcic asked on 09 Mar 2009, 08:51 AM
Is there a way to put some image in the background of the cell of the grid?

7 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 09 Mar 2009, 10:41 AM
Hello Tomislav,

You can use the following approach:
Conditional Formatting for rows/cells on ItemDataBound

Regards,
Daniel
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
tcipcic
Top achievements
Rank 1
answered on 09 Mar 2009, 11:07 AM
But I still can't find some property with wich I can display a picture in the cell(jpg or gif or something alike).
0
Daniel
Telerik team
answered on 09 Mar 2009, 12:03 PM
Hello Tomislav,

A sample code snippet in C# is shown below:
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e) 
    if (e.Item is GridDataItem) 
        e.Item.Cells[2].Style.Add("background-image""img.png"); 

Hope this helps.

Regards,
Daniel
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
tcipcic
Top achievements
Rank 1
answered on 17 Mar 2009, 01:33 PM
Thanks you Daniel,but now I have another problem.After my grid is loaded my background images are not displeyed right away,I have to click some item in the grid to view the images.
0
Daniel
Telerik team
answered on 20 Mar 2009, 03:27 PM
Hello Tcipcic,

May I examine your approach locally? In this way I will be able to provide more to-the-point answer for you. You can attach a simplified version of the project to formal support ticket.

Kind regards,
Daniel
the Telerik team

Check out Telerik Trainer , the state of the art learning tool for Telerik products.
0
Patrick Lane
Top achievements
Rank 1
answered on 15 Apr 2009, 12:27 AM
What was the result of this? Is it possible to display an image as background to a grid cell or not?

Thanks, Patrick
0
tcipcic
Top achievements
Rank 1
answered on 15 Apr 2009, 07:48 AM
Yes, it is. I opened a support ticket as Daniel suggested and we solved this issue.
The problem was that I used Server.MapPath() method to set background-image path. When I changed it to code below, it worked fine.

Here's support ticket conclusion:

--------------------------------------------------------

Thanks Pavlina for your help, this solved first issue I had.

Later I found out another issue which I succesfully solved myself. It seems that using Server.MapPath() method produces a path string which is not recognized by background-image. When I changed it to path string you see below it started working.

See code below for reference. First pathImage doesn't work in my solution, the other one does.

Thanks again,

Tom

----------------------

/*
string pathImage = System.IO.Path.Combine(Server.MapPath(ConfigurationManager.AppSettings["FolderColorImages"]),
"Small_ColorImage_" + item["colBoja"].Text + item["colStazaSlike"].Text);
*/

string pathImage = ConfigurationManager.AppSettings["FolderColorImages"] +
"/Small_ColorImage_" + item["colBoja"].Text + item["colStazaSlike"].Text;

item["colBoja"].Text = "";
item["colBoja"].Style["background-image"] = pathImage;

Tags
Grid
Asked by
tcipcic
Top achievements
Rank 1
Answers by
Daniel
Telerik team
tcipcic
Top achievements
Rank 1
Patrick Lane
Top achievements
Rank 1
Share this question
or