Click here to Skip to main content
15,891,943 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have written the code like this....

DataTable dt = new DataTable();
dt.Columns.Add("Image", typeof(string));
DataRow dr;
int i = 1;
foreach (string file in Directory.GetFiles(Server.MapPath(@"ImageUpload\")))
{
  //string nm = Path.GetFileName(file);
  dr = dt.NewRow();
  dr[0] = ResolveUrl(file);
  dt.Rows.Add(dr);
  i += 1;
}
grdimage.DataSource = dt;
grdimage.DataBind();


Here, my problem is, that the image is not displayed in grid view. Can anyone please help me out?
Posted
Updated 29-Oct-10 8:56am
v2

Just because you have an image path doesn't mean it will automatically display the image, you need to do a little work.

You have a template column that includes an Image control and you bind the src property to the Image column from your DataTable
 
Share this answer
 
Comments
Ashwin Kollaram 29-Oct-10 16:17pm    
can you please give me an example..as am a beginner
Ashwin Kollaram 29-Oct-10 17:05pm    
thanks a lot..it works
[no name] 29-Oct-10 17:52pm    
Glad it works. Now who is the moron that voted 1?
raju melveetilpurayil 6-Nov-10 22:03pm    
I given my 5.
check this.


DataTable dt = new DataTable();
        dt.Columns.Add(new DataColumn("Image", typeof(string)));
        DataRow dr;
        int i = 0;
        foreach (string file in Directory.GetFiles(Server.MapPath(@"ImageUpload\")))
        {
            dr = dt.NewRow();
            dt.Rows.Add(dr);
            dr["Image"] = "ImageUpload/" + System.IO.Path.GetFileName(file);
            i += 1;
        }
        GridView1.DataSource = dt;
        GridView1.DataBind();





XML
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false">
      <Columns>
          <asp:ImageField  DataImageUrlField="Image">
          </asp:ImageField>
      </Columns>
  </asp:GridView>
 
Share this answer
 
Comments
Ashwin Kollaram 29-Oct-10 17:08pm    
but here my prob is....i want to place radio buttons for each image so as i can delete, copy.

can you please solve this....
raju melveetilpurayil 29-Oct-10 17:19pm    
Ashwin Kollaram, just try yourself. if you face any situation we are here.. don't worry about that.. and also try to google your problem.
Take a look at THIS[^] or THIS[^] Article ,Join THIS[^] thread.

I think you might get out of all your doubts.

Please vote and Accept Answer if it Helped.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900