Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Datagrid - Duplicate images

Status
Not open for further replies.

croydon

Programmer
Apr 30, 2002
253
EU
I am using VS.NET to build an application that contains a DataGrid with a column showing images based on the path (text field) from a column in the database table (Jet 4.0).

I used the Property Builder to format the DataGrid, then Edit Template (Item Template) and Data Bindings to attach the image column to the database column as ImageURL.

The Binding is:

DataBinder.Eval(DataSet11, "Tables[qryProperty_Record].DefaultView.[0].Photo")

I have three test records in the table with different text and image paths. The problem is, when I display the page, the text is correct but the image displayed is the same for all records, i.e. the photo from the first record read.

Any suggestions would be appreciated.
 
try to do a right click on the X mark that appears instead of the image. choose properties, what path is printed there? is it a phyiscal path?

if yes then you have to use Server.Mappath() to change the same into a virtual path...

Known is handfull, Unknown is worldfull
 
The HTML for the photo column is:

<asp:Image id=Image6 runat="server" ImageUrl='<%# DataBinder.Eval(DataSet11, "Tables[qryProperty_Record].DefaultView.[0].Photo") %>'>

In the DataBindings, the Photo field has bindable Properties of "ImageURL"

I have added no other VB code relating to the Photo data. I used the DataGrid builder and properties for the display.
 
oh no, i want the properties from the browser (when you run the ASPX file in your browser)...

Known is handfull, Unknown is worldfull
 
Ok, a couple of points...

There is no "X mark that appears instead of the image". I have three records displayed in the grid. Each shows a photo image, but in all cases it is the same image. This is what is wrong.

The IE properties of the of the three images are:


This should be p0001.jpg, p0002.jpg and p0003.jpg. p0001.jpg relates to the first record displayed.

I have added an additional column to the grid to display the 'image_path' from the table. The data displayed in this column is correct, but the image column just does not seem to be binding to the 'image_path' correctly.

Thanks for your help.
 
hmm, thats strange, try giving an output in the same column, and one more thing, do you fire any javascript by any chance? that might also cause this scenario...

Known is handfull, Unknown is worldfull
 
Sorry, I don't know what you mean by "try giving an output in the same column".

As regards Javascript, I have alot of other controls on the form (mouseovers, etc) so I decided to create a new clean page with just an oledbdataadapter, oledbconnection, dataset, datagrid and a button.

Unfortunately, I still get the problem. The first photo is displayed on all lines. The HTML for the image is:
<ItemTemplate>
<asp:Image id=Image1 runat="server" ImageUrl='<%# DataBinder.Eval(DataSet11, "Tables[tblProperty_Record].DefaultView.[0].Photo") %>'>
</asp:Image>
</ItemTemplate>

The button populates the data:
OleDbDataAdapter1.Fill(DataSet11, "tblProperty_Record")
DataGrid1.DataBind()

 
I've resolved the problem. It was caused because in EditTemplate I used the dataset|default view|table|field to identify the field. It should be container|field.

So the HTML should be:

<asp:Image id=Image6 runat="server" ImageUrl='<%# DataBinder.Eval(Container, "DataItem.Photo") %>'>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top