Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > How to put an image in a GridView

Reply
Thread Tools

How to put an image in a GridView

 
 
Parrot
Guest
Posts: n/a
 
      07-08-2006
I cannot get an image to display in a column of my GridView control. I build
the fields at run time and create a table containing my data and then bind it
to the Gridview. My cod e is shown below:

DataTable dt = dataSet1.Tables.Add("Imagetable");
dt.Columns.Add(new DataColumn("File path", typeof(string)));
dt.Columns.Add(new DataColumn("Image file",
typeof(System.Web.UI.WebControls.Image)));

// this is a loop
{

DataRow dr = dataSet1.Tables["Imagetable"].NewRow();

dr[0] = name.ToString();
System.Web.UI.WebControls.Image image = new
System.Web.UI.WebControls.Image();
image.ImageUrl = dirpath + name;
image.Height = 50;
image.Visible = true;
dr[1] = image;
dataSet1.Tables["Imagetable"].Rows.A dd(dr);
}

DataView v = new DataView(dt);
GridView1.DataSource = v;
GridView1.DataBind();

My first column displays ok but the second column which is the image column
does not even display a column at all or even the heading. Does anyone know
what the problem is?
 
Reply With Quote
 
 
 
 
Ken Cox [Microsoft MVP]
Guest
Posts: n/a
 
      07-09-2006
> dt.Columns.Add(new DataColumn("Image file",
> typeof(System.Web.UI.WebControls.Image)));


Is System.Web.UI.WebControls.Image a legal datatype value? Shouldn't it be
Byte?

http://msdn.microsoft.com/library/de...atypetopic.asp

Ken
Microsoft MVP [ASP.NET]

"Parrot" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>I cannot get an image to display in a column of my GridView control. I
>build
> the fields at run time and create a table containing my data and then bind
> it
> to the Gridview. My cod e is shown below:
>
> DataTable dt = dataSet1.Tables.Add("Imagetable");
> dt.Columns.Add(new DataColumn("File path", typeof(string)));
> dt.Columns.Add(new DataColumn("Image file",
> typeof(System.Web.UI.WebControls.Image)));
>
> // this is a loop
> {
>
> DataRow dr = dataSet1.Tables["Imagetable"].NewRow();
>
> dr[0] = name.ToString();
> System.Web.UI.WebControls.Image image = new
> System.Web.UI.WebControls.Image();
> image.ImageUrl = dirpath + name;
> image.Height = 50;
> image.Visible = true;
> dr[1] = image;
> dataSet1.Tables["Imagetable"].Rows.A dd(dr);
> }
>
> DataView v = new DataView(dt);
> GridView1.DataSource = v;
> GridView1.DataBind();
>
> My first column displays ok but the second column which is the image
> column
> does not even display a column at all or even the heading. Does anyone
> know
> what the problem is?



 
Reply With Quote
 
 
 
 
Parrot
Guest
Posts: n/a
 
      07-09-2006
I tried changing the datatype to byte but that resulted in a data exception.
In a nutshell I cannot get an image file to display at all if I define it
dynamically in a table. I tried the approach suggested by another writer in
this forum in which I created an Image file when defining the Gridview using
the Smart tag editing feature. Then I assigned to the DataImageUrl Field the
name of a string field which I dynamically created at run time in the same
way that I created the image field that wouldn't work. By using this
approach I assigned to this string field the path of the image file that I
wish to display. This approach worked for some of the image files but not
all of them. I could not find a pattern as to why some image files would
display and some not - they all went through a loop of the file directory. I
am at a loss as to what to do next. What should be a simple procedure is
turning into another time burning process. I can tell you that Visual Studio
2005 has been a very time consuming and frustrating tool to work with,
especially in converting existing applications from VS 2003. In retrospect I
wished that I had left everything under 2003. The fact that I have to upload
cs files as well as aspx files to the server was not at all intuitive to me
and seems to a step backwards. VS 2005 is not ready for prime time.



"Ken Cox [Microsoft MVP]" wrote:

> > dt.Columns.Add(new DataColumn("Image file",
> > typeof(System.Web.UI.WebControls.Image)));

>
> Is System.Web.UI.WebControls.Image a legal datatype value? Shouldn't it be
> Byte?
>
> http://msdn.microsoft.com/library/de...atypetopic.asp
>
> Ken
> Microsoft MVP [ASP.NET]
>
> "Parrot" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> >I cannot get an image to display in a column of my GridView control. I
> >build
> > the fields at run time and create a table containing my data and then bind
> > it
> > to the Gridview. My cod e is shown below:
> >
> > DataTable dt = dataSet1.Tables.Add("Imagetable");
> > dt.Columns.Add(new DataColumn("File path", typeof(string)));
> > dt.Columns.Add(new DataColumn("Image file",
> > typeof(System.Web.UI.WebControls.Image)));
> >
> > // this is a loop
> > {
> >
> > DataRow dr = dataSet1.Tables["Imagetable"].NewRow();
> >
> > dr[0] = name.ToString();
> > System.Web.UI.WebControls.Image image = new
> > System.Web.UI.WebControls.Image();
> > image.ImageUrl = dirpath + name;
> > image.Height = 50;
> > image.Visible = true;
> > dr[1] = image;
> > dataSet1.Tables["Imagetable"].Rows.A dd(dr);
> > }
> >
> > DataView v = new DataView(dt);
> > GridView1.DataSource = v;
> > GridView1.DataBind();
> >
> > My first column displays ok but the second column which is the image
> > column
> > does not even display a column at all or even the heading. Does anyone
> > know
> > what the problem is?

>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
why does the following with Queue, q.put('\x02', True) not put itin the queue? Gabriel Rossetti Python 3 04-25-2008 03:41 PM
put gridview into reportviewer Andrew Han ASP .Net 0 03-05-2008 01:15 AM
GridView Footer - Put a link into the Edit / Delete column Remy ASP .Net 2 06-14-2006 05:51 PM
GridView Hierarchical View - Gridview in Gridview =?Utf-8?B?bWdvbnphbGVzMw==?= ASP .Net 1 05-09-2006 06:48 PM



Advertisments