We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,473 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Image within a Gridview Control

Hey,

im trying to dynamically add an image to a gridview for each row if it meets a condition.

DataTable dtSub = new DataTable();
dtSub.Columns.Add("ID", Type.GetType("System.String"));
dtSub.Columns.Add("FirstName", Type.GetType("System.String"));
dtSub.Columns.Add("LastName", Type.GetType("System.String"));
dtSub.Columns.Add("Tutor", Type.GetType("System.String"));
dtSub.Columns.Add("test", typeof(System.Web.UI.WebControls.Image)); //not sure if this is correct??
DataSet ds = new DataSet();
ds.Tables.Add(dtSub);
Session["myds"] = ds;



foreach (var item in GetDataItem)
{
   int studIDconflict = item.stud_id; //get the id


    if (count != studIDconflict)//compare both ids
       {
             System.Web.UI.WebControls.Image img = new System.Web.UI.WebControls.Image();
             img.ResolveUrl("~/images/star.png");
             img.ToolTip = "dd";
             dtSub.Rows[dtSub.Rows.Count - 1]["test"] = img;

            //dtSub.Rows[dtSub.Rows.Count - 1]["test"] = ResolveUrl("~/images/star.png");   
            //HyperLink planLink = (HyperLink)dtSub.Rows[dtSub.Rows.Count - 1]["test"];
            //planLink.ImageUrl = string.Format("~/Images/{0}.jpg", ID);
            //planLink.ImageUrl = ResolveUrl("~/images/star.png");
            // planLink.ToolTip = "le testing";
            //planLink.ImageUrl = string.Format("~/images/star.png");
        }
}

I have tried so many different things, its possible if i add an <asp:image> to the html but if the condition is not met the image control still apears but without the image. This is why i want the control to be created only is the condition is met.

im unsure how to link the new instance of an image control to the gridview columns, most things iv found online are binding images via the database. Anyone able to help?

2
Contributors
1
Reply
1 Day
Discussion Span
1 Year Ago
Last Updated
2
Views
barriegrant1
Light Poster
34 posts since Jan 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

You need to add the Image control into GridView's TemplateField or just use ImageField.

__avd
Posting Genius (adatapost)
Moderator
8,736 posts since Oct 2008
Reputation Points: 2,141
Solved Threads: 1,262
Skill Endorsements: 50

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.0781 seconds using 2.7MB