Home | Articles|Namespace|Interview Questions|Tools|Jobs|Projects|Community
Asp.net Tutorials

»Dotnet Ads
»Message Boards
Message Boards
Dotnet Books

»Member Details
Register
Login
LogOut
Submit Code
Submit Jobs
Submit Projects

»Competition
Community
Winners
Prizes
Write For Us
Members

»Other Resources
Links
Dotnet Resources


Forums»C# .NET »



Adding image to a datagrid

You will want to use an TemplateColumn and ItemTemplate to display a specific control within a datagrid.

datagrid id="dgGrid" runat="server"
Columns
TemplateColumn
ItemTemplate
Image id="imgImage1" runat="server" /Image
ItemTemplate
TemplateColumn
Columns
datagrid

NOTE: I ommitted the following syntax items from the code above <>, , and asp: for each control.

Then in the code behind you will need to create a method that will Bind this control to the grid.

Create a method like this.
private void BindTemplateColumn()
{
create a for loop to iterate through each row of the datagird and include the code below within the for loop
then you will need to assign the properties of your image
System.Web.UI.WebControls.Image img1 = (System.Web.UI.WebControls.Image)dgGrid.Items[i].FindControl("imgImage1");
img1.ImageUrl = "yahoo.bmp";

}

Now call this method after the DataBind() method of your datagrid.

dgGrid.DataBind();
BindTemplateColumn();

Hope this helped.
Nathan
posted by:Nathan  on 5/8/2007 12:00:00 AM
© 2008 dotnetwatch.com -- Privacy policy

Website Design & Internet Marketing by Shivam