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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Image in datagrid 1

Status
Not open for further replies.

peekay

Programmer
Oct 11, 1999
324
ZA
I am trying to show an image in my datagrid, but the error -Tag is not well formed - occurs. Can somebody please help.

<asp:TemplateColumn>
<ItemTemplate>
<asp:Image Runat="server" ImageUrl="images/" & "<%# GetImage(DataBinder.Eval(Container,"DataItem.photoname").ToString()) %>"
</asp:image></ItemTemplate></asp:TemplateColumn>

Thanks

PK Odendaal
 
PK: I use the following successfully to bring images into the Datagrid:

<%# DataBinder.Eval(Container.DataItem, "ImagePath")%>

Perhaps its a minor syntax problem --

Another technique re: images in DataGrids is to place an image based on a field value (using a code behind function to fill the grid's template columen), e.q.,

In the code behind:
Code:
    Protected Function getMap(Latitude As Object) As String
         If IsDBNull(Latitude) Then
            Return "Images/TNmap.gif"
        Else
            Return "Images/Tmap.bmp"
        End If
     End Function

And then in the DataGrid's template column call the function and place the image, q.v.,

Code:
<asp:TemplateColumn HeaderText="Map!">
<HeaderStyle horizontalalign="Center" verticalalign="Middle"></HeaderStyle>
<ItemStyle horizontalalign="Center"></ItemStyle>                   <ItemTemplate>
<asp:Image id="imgTiger" Runat="Server" ImageUrl=<%# getMap(Container.DataItem("Latitude")) %>/>
</ItemTemplate>
</asp:TemplateColumn>
 
Thanks Isadore

I have a dataset bound to the datagrid in code behind and one of the fields is imagename.

In the datagrid I have added a hyperlink to the item template. Somehow I cannot succeed in getting the imageurl of the hyperlink right.

This is my latest code :

In code behind :

cmdSelect = New OleDbCommand("SELECT * from listings where catno=" & Request.QueryString("ID") & " order by startdate desc", Cn)
Cn.Open()
dgListings.DataSource = cmdSelect.ExecuteReader()
dgListings.DataBind()
Cn.Close()

In the html I have :

<asp:HyperLink id="HyperLink1" runat="server" Height="150px" Width="150px" imageurl='<# DataBinder.Eval(Container.DataItem, "photoname") %>'>HyperLink</asp:HyperLink>


Thanks for your help






PK Odendaal
 
peekay: was just working up a test grid; what was the final solution / problem?
 
Hi Isadore

Here was the final one :

<asp:HyperLink id="HyperLink1" runat="server" Height="150px" imageurl='<%# DataBinder.Eval(Container.DataItem, "photoname") %>' Width="150px" >
</asp:HyperLink>

I also got the first label control on column(1) right, but I still have some problems inserting a second label control in the third column and/or concatenating two datafields with the container.dataitem

Could you give me some advice on that ?

Thanks





PK Odendaal
 
peekay: one trick you might use for concatenating is to do it in the SQL statement, e.g.,

SELECT.... FieldA & '-' & Field B As MyFields, x, y, ...

I have seen concatenation in container items discussed from time to time, do a "Search" using DataBinder and parse through a couple of them, there should be quite a number of examples.

See what you can dig up on a search - I think it is customary to use the '+' syntax inside the Container; let me know if you have any luck; otherwise I'll take another look.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top