how to add image in gridview after checking a condition

Posted by Klbaiju under ASP.NET on 8/30/2012 | Points: 10 | Views : 2560 | Status : [Member] | Replies : 1
Hi, in my application,
i want to display some data in gridview.there is an image column in gridview.
i want to add an image in that column after checking the particular id is in a folder.

ie a folder named pdf and that contains 2.pdf,3.pdf . i have 5 records with id 1,2,3,4,5.
in 2 an 3 i want to display an image. rest of records that that column should be blank.

how it is possible.


Regards

Baiju




Responses

Posted by: Ranjeet_8 on: 8/30/2012 [Member] [MVP] Gold | Points: 25

Up
0
Down
u can check ur condition on GridView RowDataBound Event
 

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
Label lblID = (Label)e.Row.FindControl("Your_lblIDName"); //find control inside GridView
Image img = (Image)e.Row.FindControl("Your_imgName"); //find control inside GridView
if (lblID != null)
{
if (lblID.Text == "2" || lblID.Text == "3")
img.ImageUrl = "Set ur image url here.";
else
img.Visible = false;
}
}


Klbaiju, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response