Home All Groups Group Topic Archive Search About

Setting background image for gridvew cell

Author
17 Sep 2007 11:10 AM
Anup Daware
Hi,

I need to set the background image of the grid view cell according to
the data. Is there any way to do this?

Thanks,
Anup

Author
17 Sep 2007 2:58 PM
David R. Longnecker
Use the RowDataBound method.  Replace the Cell array value and "images/"
path to where your images are really located.

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
            string imageName = e.Row.Cells[1].Text;
            e.Row.Cells[1].Attributes.Add("Style", "background-image: url('images/"
+ imageName + "')");
}

HTH.

-dl

--
David R. Longnecker
http://blog.tiredstudent.com

Show quote
> Hi,
>
> I need to set the background image of the grid view cell according to
> the data. Is there any way to do this?
>
> Thanks,
> Anup

AddThis Social Bookmark Button