hi!
how to display image in datagrid by using templatefield. i take one image control in itemtemplate field. please give a code
thanks.
Template field
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Raaj KumarRank #7,836 · 233 reputationPosted Feb 20, 2010, 3:58 AM EST
Below is asp code,
and in code behind, I created a sample class for testing. You can modify it for your convinience,
public class Employee
{
public String Name { get; set; }
public String Age { get; set; }
public string ImageUrl { get; set; }
}
protected void Page_Load(object sender, EventArgs e)
{
IList < Employee > empList = new List
empList.Add(new Employee() { Name = "Name1", Age = "12", ImageUrl = "~/Images/Dog.gif" });
empList.Add(new Employee() { Name = "Name2", Age = "12", ImageUrl = "~/Images/Dog1.gif" });
empList.Add(new Employee() { Name = "Name3", Age = "12", ImageUrl = "~/Images/Dog2.jpg" });
empList.Add(new Employee() { Name = "Name4", Age = "12", ImageUrl = "~/Images/Dog3.jpg" });
if (!IsPostBack)
{
GridView1.DataSource = empList;
GridView1.DataBind();
}
}
Here I created a folder in the project and I placed all the images inside this.
Please let me know if you want more help
Regards,
Raaj