Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

image field and sqldatasource

3 views
Skip to first unread message

yefei

unread,
Mar 28, 2006, 11:58:43 PM3/28/06
to
I need to display images in a SQL database using a gridview
I search some examples, what they did is very simple
add an image field, then set the folowing properties

<asp:imagefield dataimageurlfield="LastName"
dataimageurlformatstring="~\Images\{0}.jpg"
alternatetext="Employee Photo"
nulldisplaytext="No image on file."
headertext="Photo"
readonly="true"/>
<asp:boundfield datafield="FirstName"
headertext="First Name"/>
<asp:boundfield datafield="LastName"
headertext="Last Name"/>
if i set the datasource of the gridview to a sqldatasource with the
folowing commands
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConflictDetection="CompareAllValues"
ConnectionString="<%$ ConnectionStrings:MyConnectionString
%>"
SelectCommand="SELECT [No_], [Picture], [Picture No_] AS Picture_No_
FROM [My Company$Item] ORDER BY [No_]

the 'Picture' is the image field, the Picture_No is used to identify
the picture, the No_ is the name of our product

and i have the following setting on my image field

<asp:ImageField DataAlternateTextField="Picture_No_"
DataImageUrlField="Picture_No_"
HeaderText="Picture" DataImageUrlFormatString="~\Image\{0}.gif">
</asp:ImageField>

i saw some example uses accessDataSource
but i think the image field should also work with sqldatasource
but when i render the gridview, the images are the Picture_No with red
cross

i am using the Visual Web Developer 2005 Express Edition in C#.Net

can someone point out what's wrong with my property settings?
especially regards to SQL Database Server

yefei

unread,
Mar 29, 2006, 2:36:33 AM3/29/06
to
I found that people are talking about the ImageUrl instead of the image
in the database

that is what stored in the database is the URL of the image instead of
the image itself

But I have no idea how an image is stored in a SQL server

Flinky Wisty Pomm

unread,
Mar 29, 2006, 7:05:22 AM3/29/06
to
A quick Google turns up this
http://www.dotnetbips.com/articles/displayarticle.aspx?id=101 as an
example of displaying images direct from the DB in a DataGrid.

I'd recommend that you store the image URL and not the image data
because you'll have less DB overhead, less mucking about with casting
to the image type, and life will generally be more pleasant.

yefei

unread,
Mar 29, 2006, 11:17:12 AM3/29/06
to
thanks very much
I am using Visual Web Developer 2005 Express edition, which does not
have DataGrid control, instead it has GridView control
the GridView control doesnot have the ItemBound event
and all the events, no one is associated with an item,

the DataList control in VWD has the itemBound event, but C#.net have no
CType function
So is there a way I can do with GridView control, or DataList control
or some hints to declare and display a DataGrid object in codes?

0 new messages