473,404 Members | 2,137 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

Binding Image to Field in Data Grid

Hi All,

I have a data grid which displays country names. I now wish to display the
country flag images above the names.

Can someone please advise how I display an image in a datagrid? I have a
folder of flag images, named in relations to the countries database ID.

Current data grid code is...

<asp:datagrid runat="server"
Id="DGCountries"
GridLines="Horizontal"
cellpadding="5"
cellspacing="0"
Headerstyle-CssClass="DataGridHeaderDefault"
BackColor="#ffffff"
BorderColor="Black"
AutogenerateColumns="False">
<Columns>
<asp:BoundColumn
DataField="Country"
HeaderText="Country" ItemStyle-CssClass="DataGridItemDefault">
</asp:BoundColumn>
</Columns>
</asp:DataGrid>

Many Thanks,
Simon.

--
-
* Please reply to group for the benefit of all
* Found the answer to your own question? Post it!
* Get a useful reply to one of your posts?...post an answer to another one
* Search first, post later : http://www.google.co.uk/groups
* Want my email address? Ask me in a post...Cos2MuchSpamMakesUFat!
Nov 18 '05 #1
3 2705
Convert the bound column to a template column, using the property builder in
the VS.NET IDE (or do it yourself in the HTML of the aspx page). Then you
can add an image control to the template column (to edit the template column
in the IDE, right click on it and choose the appropriate option (Edit
Templates I think)).

To get the flag image, you could write a small function in your codebehine,
make sure its protected so the aspx page can access it. Call this function
from a databinding statement in the datagrid template column for the
country, in the image control - something like
<%#GetCountryImageRef(DataBind.Eval(Container, "DataItem.Country") %>. (This
should go in the ImageURL part of the asp.net image control - i.e.
ImageURL="<%#GetCountryImageRef(DataBind.Eval(Cont ainer, "DataItem.Country")
%>").

Write the function to return the URL for the image (as a string) depending
on the country passed in.

I'm just doing this off the top of my head, so the details may be wrong, but
thats the general idea of one possible solution.

Let me know if you need more details, or something isn't clear

Cheers,
Pete Beech
"Simon Harris" <to*********@makesyoufat.com> wrote in message
news:u3**************@TK2MSFTNGP12.phx.gbl...
Hi All,

I have a data grid which displays country names. I now wish to display the
country flag images above the names.

Can someone please advise how I display an image in a datagrid? I have a
folder of flag images, named in relations to the countries database ID.

Current data grid code is...

<asp:datagrid runat="server"
Id="DGCountries"
GridLines="Horizontal"
cellpadding="5"
cellspacing="0"
Headerstyle-CssClass="DataGridHeaderDefault"
BackColor="#ffffff"
BorderColor="Black"
AutogenerateColumns="False">
<Columns>
<asp:BoundColumn
DataField="Country"
HeaderText="Country" ItemStyle-CssClass="DataGridItemDefault">
</asp:BoundColumn>
</Columns>
</asp:DataGrid>

Many Thanks,
Simon.

--
-
* Please reply to group for the benefit of all
* Found the answer to your own question? Post it!
* Get a useful reply to one of your posts?...post an answer to another one
* Search first, post later : http://www.google.co.uk/groups
* Want my email address? Ask me in a post...Cos2MuchSpamMakesUFat!

Nov 18 '05 #2
Hi Peter,

Thankyou very much for your (Very prompt!) reply - I am very new to ASPX, a
question if you dont mind... :)

- Whats codebehind? I've heard the term before, possibly already using
it!...

Thanks,
Simon.

"Pete Beech" <pe*********@hotmail.nojunk.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
Convert the bound column to a template column, using the property builder in the VS.NET IDE (or do it yourself in the HTML of the aspx page). Then you
can add an image control to the template column (to edit the template column in the IDE, right click on it and choose the appropriate option (Edit
Templates I think)).

To get the flag image, you could write a small function in your codebehine, make sure its protected so the aspx page can access it. Call this function
from a databinding statement in the datagrid template column for the
country, in the image control - something like
<%#GetCountryImageRef(DataBind.Eval(Container, "DataItem.Country") %>. (This should go in the ImageURL part of the asp.net image control - i.e.
ImageURL="<%#GetCountryImageRef(DataBind.Eval(Cont ainer, "DataItem.Country") %>").

Write the function to return the URL for the image (as a string) depending
on the country passed in.

I'm just doing this off the top of my head, so the details may be wrong, but thats the general idea of one possible solution.

Let me know if you need more details, or something isn't clear

Cheers,
Pete Beech
"Simon Harris" <to*********@makesyoufat.com> wrote in message
news:u3**************@TK2MSFTNGP12.phx.gbl...
Hi All,

I have a data grid which displays country names. I now wish to display the country flag images above the names.

Can someone please advise how I display an image in a datagrid? I have a
folder of flag images, named in relations to the countries database ID.

Current data grid code is...

<asp:datagrid runat="server"
Id="DGCountries"
GridLines="Horizontal"
cellpadding="5"
cellspacing="0"
Headerstyle-CssClass="DataGridHeaderDefault"
BackColor="#ffffff"
BorderColor="Black"
AutogenerateColumns="False">
<Columns>
<asp:BoundColumn
DataField="Country"
HeaderText="Country" ItemStyle-CssClass="DataGridItemDefault">
</asp:BoundColumn>
</Columns>
</asp:DataGrid>

Many Thanks,
Simon.

--
-
* Please reply to group for the benefit of all
* Found the answer to your own question? Post it!
* Get a useful reply to one of your posts?...post an answer to another one * Search first, post later : http://www.google.co.uk/groups
* Want my email address? Ask me in a post...Cos2MuchSpamMakesUFat!


Nov 18 '05 #3
Hi Simon,
The codebehind file for a given ASPX page is normally a C# or VB.NET file
containing a class which inherits from the Page object. (The .aspx page
itself actually gets converted into a class by the server, and this aspx
class inherits from the codebehind class). This is where you handle events
for the page (like button clicks, etc), and set up the page, and generally
do most of the coding for the page. You will get references for the
webcontrols you use on the page as member variables of the codebehind class,
and you can manipulate them programmatically in whatever way you want. You
could even add new webcontrols dynamically, depending on the actions of the
user.

So, if you have a page called WebForm1.aspx, the codebehind file would be
WebForm1.aspx.cs (if its a C# project) or WebForm1.aspx.vb (for VB.NET). It
depends on what tool you are using to code up your ASP.NET app - if you're
using Visual Studio .NET, that uses codebehind files. But if you use ASP.NET
webmatrix, it only supports aspx files which contain all the server side
code as well.. (maybe the latest version allows codebehind, I'm not sure).

If you're using VS.NET, and you have the aspx page open, press F7, or right
click on the page and select 'View Code' to see the codebehind file.

Hope that makes sense - you probably are already using it :-)

Cheers,
Pete

"Simon Harris" <to*********@makesyoufat.com> wrote in message
news:eS**************@TK2MSFTNGP10.phx.gbl...
Hi Peter,

Thankyou very much for your (Very prompt!) reply - I am very new to ASPX, a question if you dont mind... :)

- Whats codebehind? I've heard the term before, possibly already using
it!...

Thanks,
Simon.

"Pete Beech" <pe*********@hotmail.nojunk.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
Convert the bound column to a template column, using the property builder
in
the VS.NET IDE (or do it yourself in the HTML of the aspx page). Then you can add an image control to the template column (to edit the template

column
in the IDE, right click on it and choose the appropriate option (Edit
Templates I think)).

To get the flag image, you could write a small function in your

codebehine,
make sure its protected so the aspx page can access it. Call this function from a databinding statement in the datagrid template column for the
country, in the image control - something like
<%#GetCountryImageRef(DataBind.Eval(Container, "DataItem.Country") %>.

(This
should go in the ImageURL part of the asp.net image control - i.e.
ImageURL="<%#GetCountryImageRef(DataBind.Eval(Cont ainer,

"DataItem.Country")
%>").

Write the function to return the URL for the image (as a string) depending on the country passed in.

I'm just doing this off the top of my head, so the details may be wrong,

but
thats the general idea of one possible solution.

Let me know if you need more details, or something isn't clear

Cheers,
Pete Beech
"Simon Harris" <to*********@makesyoufat.com> wrote in message
news:u3**************@TK2MSFTNGP12.phx.gbl...
Hi All,

I have a data grid which displays country names. I now wish to display

the country flag images above the names.

Can someone please advise how I display an image in a datagrid? I have a folder of flag images, named in relations to the countries database ID.
Current data grid code is...

<asp:datagrid runat="server"
Id="DGCountries"
GridLines="Horizontal"
cellpadding="5"
cellspacing="0"
Headerstyle-CssClass="DataGridHeaderDefault"
BackColor="#ffffff"
BorderColor="Black"
AutogenerateColumns="False">
<Columns>
<asp:BoundColumn
DataField="Country"
HeaderText="Country" ItemStyle-CssClass="DataGridItemDefault">
</asp:BoundColumn>
</Columns>
</asp:DataGrid>

Many Thanks,
Simon.

--
-
* Please reply to group for the benefit of all
* Found the answer to your own question? Post it!
* Get a useful reply to one of your posts?...post an answer to another one * Search first, post later : http://www.google.co.uk/groups
* Want my email address? Ask me in a post...Cos2MuchSpamMakesUFat!



Nov 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Jesse | last post by:
Hi All, I've been working on a form that has several bound controls that all link to one table in a dataset. In the table, there is a column for the filename of jpeg images related to each...
0
by: Ann Morris | last post by:
INTRODUCTION One of the most powerful aspects of .NET and Windows Forms is data binding. Data binding is the process of associating user interface (UI) elements with a data source to generate a...
3
by: Shravan | last post by:
Hi, How can I bind DataRow array to ComboBox. I tried setting DataSource -> DataRow Array DisplayMember -> ColumnName But it was showing "System.Data.DataRow" for every item in the...
1
by: Parveen | last post by:
I noticed that any formatting of the grid before data binding is lost after the grid is bound to a data table in the dataset. Is it possible to format the appearance of the data that shows up in...
1
by: Bruce | last post by:
Hi, there, I meet a problem about comboBox binding. -------------------- Database: Northwind Tables: 1) Products 2) Categories I create a form (named "form1") to edit the record from...
5
by: Amit | last post by:
Hello, I have a simple search screen, with two drop-downs and a text box. There's also a GridView control that is using a SqlDataSource control to show the matching results. The SqlDataSource uses...
0
by: Andrew | last post by:
Hello Ive been messing around with a simple raw image viewer using Pil and Tkinter However I am running into problems displaying the images they appear to be not correct I believe it is cause of...
1
by: =?Utf-8?B?cmFuZHkxMjAw?= | last post by:
I'm working in Visual Studio 2005 and C#. I have a DataSet, a Binding Source, and a grid. I'm finding that if a table in the DataSet gets updated from the Database, the new data doesn't appear in...
0
by: tavares | last post by:
(Our apologies for cross-posting. We appreciate if you kindly distribute this information by your co- workers and colleagues.) ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.