Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8957857
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T15:05:18+00:00 2026-06-15T15:05:18+00:00

I want to add image to GridView cell with below code but doesn’t show

  • 0

I want to add image to GridView cell with below code but doesn’t show image

//aspx
 <asp:TemplateField HeaderText="image">
      <ItemTemplate>
          <asp:Image ID="img" runat="server" Width="100px" Height="100px" />
      </ItemTemplate>

//.cs -> In page_Load

for (int i = 0; i < GridView1.Rows.Count; i++)
{
      Image img = (Image)GridView1.Rows[i].FindControl("img");
      img.ImageUrl = path of image;
 }//for
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T15:05:19+00:00Added an answer on June 15, 2026 at 3:05 pm

    You can use RowDataBound event to change something inside a GridView Row.

    protected void GridView1_RowDatabound(object sender, GridViewRowEventArgs e)
    {
        // check if this row is a row with Data (not Header or Footer)
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            // find your Image control in the Row
            Image image = ((Image)e.Row.FindControl("img"));
            // set the path of image
            img.ImageUrl = "path of image";     
        }
    }
    

    Or you can use a foreach statment to loop in Rows collection and change the path of image. this code could be on the Page_Load event.

    foreach(GridViewRow row in GridView1.Rows)
    { 
        // check if this row is a row with Data (not Header or Footer)
        if (row.RowType == DataControlRowType.DataRow)
        {
            // find your Image control in the Row
            Image image = ((Image)row.FindControl("img"));
            // set the path of image
            img.ImageUrl = "path of image";     
        }
    }
    

    Edits

    You cannot set the image out of the solution. Do to this, you have to create an Handler (.ashx file) and pass the name of your image on C: and return the a byte[], something like this:

    public void ProcessRequest(HttpContext context)
    {
        byte[] imageBytes = File.ReadAllBytes(@"C:\" + context.Request["image"]);
        context.Response.ContentType = "image/png";
        context.Response.BinaryWrite(imageBytes);
    }
    

    And on your page, set it by handler passing a image parameter in url:

    Image image = ((Image)row.FindControl("img"));
    img.ImageUrl = "ImageHandler.ashx?image=1.png";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi I want to add image in table cell according to condition in table.
I want to add an image to the slide thumbnail in left panel, but
I have a panel in asp page and I want to add image to
I want to add an image onto another image. But I know that imageview
I want to add image in directory. The directory makes dynamically. But there is
I want to add an image, instead of the default button. I already have
I want to add background image to uinavigationcontroller. Please help me.
I want to add an image to be a background of the header, the
I want to add a background image to a bar chart using Highcharts and
I am very new to Java, I want to add a PNG image to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.