473,772 Members | 2,414 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

set ASP.NET datagrid image based on SQL table value

I have an ASP.NET datagrid that loads an image. I would like to load
one image if the value in my SQL table is true and another if it is
false. Here is my code.

<%@ Page Language="vb" AutoEventWireup ="false"
Codebehind="Sea rch.aspx.vb" Inherits="PROJE CT.WebForm1"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>WebForm1 </title>
<meta name="GENERATOR " content="Micros oft Visual Studio .NET 7.1">
<meta name="CODE_LANG UAGE" content="Visual Basic .NET 7.1">
<meta name="vs_defaul tClientScript" content="VBScri pt">
<meta name="vs_target Schema"
content="http://schemas.microso ft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING= "GridLayout ">
<form id="Form1" method="post" runat="server">
<asp:DataGrid id="MyGrid" style="Z-INDEX: 101; LEFT: 0px; POSITION:
absolute; TOP: 0px" runat="server"
BorderColor="#D EBA84" BorderStyle="No ne" BorderWidth="1p x"
BackColor="#DEB A84" CellPadding="3"
AutoGenerateCol umns="False" CellSpacing="2" >
<SelectedItemSt yle Font-Bold="True" ForeColor="Whit e"
BackColor="#738 A9C"></SelectedItemSty le>
<ItemStyle ForeColor="#8C4 510" BackColor="#FFF 7E7"></ItemStyle>
<HeaderStyle Font-Bold="True" ForeColor="Whit e"
BackColor="#A55 129"></HeaderStyle>
<FooterStyle ForeColor="#8C4 510"
BackColor="#F7D FB5"></FooterStyle>
<Columns>
</asp:BoundColumn >
<asp:BoundColum n DataField="City " ReadOnly="True" HeaderText="Cit y">
<ItemStyle Width="150px"></ItemStyle>
</asp:BoundColumn >
<asp:TemplateCo lumn HeaderText="Che ck or X">
<ItemTemplate >
<img src='\Check.gif '>
</ItemTemplate>
</asp:TemplateCol umn>
</Columns>
<PagerStyle HorizontalAlign ="Center" ForeColor="#8C4 510"
Mode="NumericPa ges"></PagerStyle>
</asp:DataGrid>
</form>
</body>
</HTML>

I want to show the 'Check.gif' if an SQL table value is True or
'x.gif' if it is false.

Thaks for any help, This ASP.NET is kicking my butt.
Nov 18 '05 #1
3 2506
Hi Rob,

Just jam a little

<IMG src='<%#iif(Dat aBinder.Eval(Co ntainer,
"DataItem.Boole an"),"Check.gif ","x.gif") %>'>

in there and you should be okay.

BTW, I had some problems with your markup. My fixed version is below.

Does this help?

Ken
Microsoft MVP [ASP.NET]
Toronto
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>WebForm1 </title>
<meta name="GENERATOR " content="Micros oft Visual Studio .NET 7.1">
<meta name="CODE_LANG UAGE" content="Visual Basic .NET 7.1">
<meta name="vs_defaul tClientScript" content="VBScri pt">
<meta name="vs_target Schema"
content="http://schemas.microso ft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING= "GridLayout ">
<form id="Form1" method="post" runat="server">
<asp:DataGrid id="MyGrid" runat="server" BorderColor="#D EBA84"
BorderStyle="No ne" BorderWidth="1p x"
BackColor="#DEB A84" CellPadding="3" AutoGenerateCol umns="False"
CellSpacing="2" >
<SelectedItemSt yle Font-Bold="True" ForeColor="Whit e"
BackColor="#738 A9C"></SelectedItemSty le>
<ItemStyle ForeColor="#8C4 510" BackColor="#FFF 7E7"></ItemStyle>
<HeaderStyle Font-Bold="True" ForeColor="Whit e"
BackColor="#A55 129"></HeaderStyle>
<FooterStyle ForeColor="#8C4 510" BackColor="#F7D FB5"></FooterStyle>
<Columns>
<asp:BoundColum n DataField="City " ReadOnly="True" HeaderText="Cit y">
<ItemStyle Width="150px"></ItemStyle>
</asp:BoundColumn >
<asp:TemplateCo lumn HeaderText="Che ck or X">
<ItemTemplate >
<IMG src='<%#iif(Dat aBinder.Eval(Co ntainer,
"DataItem.Boole an"),"Check.gif ","x.gif") %>'>
</ItemTemplate>
</asp:TemplateCol umn>
</Columns>
<PagerStyle HorizontalAlign ="Center" ForeColor="#8C4 510"
Mode="NumericPa ges"></PagerStyle>
</asp:DataGrid>
</form>
</body>
</HTML>

"Rob Rogers" <ro*@natltc.com > wrote in message
news:7e******** *************** ***@posting.goo gle.com...
I have an ASP.NET datagrid that loads an image. I would like to load
one image if the value in my SQL table is true and another if it is
false. Here is my code.

<%@ Page Language="vb" AutoEventWireup ="false"
Codebehind="Sea rch.aspx.vb" Inherits="PROJE CT.WebForm1"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>WebForm1 </title>
<meta name="GENERATOR " content="Micros oft Visual Studio .NET 7.1">
<meta name="CODE_LANG UAGE" content="Visual Basic .NET 7.1">
<meta name="vs_defaul tClientScript" content="VBScri pt">
<meta name="vs_target Schema"
content="http://schemas.microso ft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING= "GridLayout ">
<form id="Form1" method="post" runat="server">
<asp:DataGrid id="MyGrid" style="Z-INDEX: 101; LEFT: 0px; POSITION:
absolute; TOP: 0px" runat="server"
BorderColor="#D EBA84" BorderStyle="No ne" BorderWidth="1p x"
BackColor="#DEB A84" CellPadding="3"
AutoGenerateCol umns="False" CellSpacing="2" >
<SelectedItemSt yle Font-Bold="True" ForeColor="Whit e"
BackColor="#738 A9C"></SelectedItemSty le>
<ItemStyle ForeColor="#8C4 510" BackColor="#FFF 7E7"></ItemStyle>
<HeaderStyle Font-Bold="True" ForeColor="Whit e"
BackColor="#A55 129"></HeaderStyle>
<FooterStyle ForeColor="#8C4 510"
BackColor="#F7D FB5"></FooterStyle>
<Columns>
</asp:BoundColumn >
<asp:BoundColum n DataField="City " ReadOnly="True" HeaderText="Cit y">
<ItemStyle Width="150px"></ItemStyle>
</asp:BoundColumn >
<asp:TemplateCo lumn HeaderText="Che ck or X">
<ItemTemplate >
<img src='\Check.gif '>
</ItemTemplate>
</asp:TemplateCol umn>
</Columns>
<PagerStyle HorizontalAlign ="Center" ForeColor="#8C4 510"
Mode="NumericPa ges"></PagerStyle>
</asp:DataGrid>
</form>
</body>
</HTML>

I want to show the 'Check.gif' if an SQL table value is True or
'x.gif' if it is false.

Thaks for any help, This ASP.NET is kicking my butt.


Nov 18 '05 #2
BTW, here's the code behind and data source that I used for that example.
"Boolean" is the name of the field as well as the type.

Private Sub Page_Load _
(ByVal sender As System.Object, _
ByVal e As System.EventArg s) _
Handles MyBase.Load
MyGrid.DataSour ce = CreateDataSourc e()
MyGrid.DataBind ()

End Sub
Function CreateDataSourc e() As DataTable
Dim dt As New DataTable
Dim dr As DataRow
dt.Columns.Add( New DataColumn _
("IntegerValue" , GetType(Int32)) )
dt.Columns.Add( New DataColumn _
("City", GetType(String) ))
dt.Columns.Add( New DataColumn _
("CurrencyValue ", GetType(Double) ))
dt.Columns.Add( New DataColumn _
("Boolean", GetType(Boolean )))
Dim i As Integer
For i = 0 To 8
dr = dt.NewRow()
dr(0) = i
dr(1) = "Item " + i.ToString()
dr(2) = 1.23 * (i + 1)
dr(3) = (i = 4)
dt.Rows.Add(dr)
Next i
Return dt
End Function 'CreateDataSour ce

"Rob Rogers" <ro*@natltc.com > wrote in message
news:7e******** *************** ***@posting.goo gle.com...
I have an ASP.NET datagrid that loads an image. I would like to load
one image if the value in my SQL table is true and another if it is
false. Here is my code.

<%@ Page Language="vb" AutoEventWireup ="false"
Codebehind="Sea rch.aspx.vb" Inherits="PROJE CT.WebForm1"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>WebForm1 </title>
<meta name="GENERATOR " content="Micros oft Visual Studio .NET 7.1">
<meta name="CODE_LANG UAGE" content="Visual Basic .NET 7.1">
<meta name="vs_defaul tClientScript" content="VBScri pt">
<meta name="vs_target Schema"
content="http://schemas.microso ft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING= "GridLayout ">
<form id="Form1" method="post" runat="server">
<asp:DataGrid id="MyGrid" style="Z-INDEX: 101; LEFT: 0px; POSITION:
absolute; TOP: 0px" runat="server"
BorderColor="#D EBA84" BorderStyle="No ne" BorderWidth="1p x"
BackColor="#DEB A84" CellPadding="3"
AutoGenerateCol umns="False" CellSpacing="2" >
<SelectedItemSt yle Font-Bold="True" ForeColor="Whit e"
BackColor="#738 A9C"></SelectedItemSty le>
<ItemStyle ForeColor="#8C4 510" BackColor="#FFF 7E7"></ItemStyle>
<HeaderStyle Font-Bold="True" ForeColor="Whit e"
BackColor="#A55 129"></HeaderStyle>
<FooterStyle ForeColor="#8C4 510"
BackColor="#F7D FB5"></FooterStyle>
<Columns>
</asp:BoundColumn >
<asp:BoundColum n DataField="City " ReadOnly="True" HeaderText="Cit y">
<ItemStyle Width="150px"></ItemStyle>
</asp:BoundColumn >
<asp:TemplateCo lumn HeaderText="Che ck or X">
<ItemTemplate >
<img src='\Check.gif '>
</ItemTemplate>
</asp:TemplateCol umn>
</Columns>
<PagerStyle HorizontalAlign ="Center" ForeColor="#8C4 510"
Mode="NumericPa ges"></PagerStyle>
</asp:DataGrid>
</form>
</body>
</HTML>

I want to show the 'Check.gif' if an SQL table value is True or
'x.gif' if it is false.

Thaks for any help, This ASP.NET is kicking my butt.


Nov 18 '05 #3
Thanks, Thats just what I needed.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 18 '05 #4

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

Similar topics

5
2597
by: Jeff | last post by:
IDE: VS 2003 :NET OS: XP Pro My app have a form with a tab-control on it. The tab-control have 2 tabpages. One of the tabpages displays a datagrid, and the other tabpage displays details (order date, name, address etc) about the selected row in the datagrid... My problem is when I enter a new record in the details tabpage (saves data to database), and go back to the datagrid. Only the data from the PM-table
4
4739
by: Trevor Hartman | last post by:
hi, I want to display certain data in my edititemtemplate in the datagrid based on the value of a column. How do I do an if then inside the datagrid AND test the value of the current column. i only know how to refer to columsn with the <%# DataBinder.Eval(Container.DataItem, "column") %>, and i can't include an if then in the <%# %> block. any suggestions? thanks -trevor
8
2408
by: pmud | last post by:
Hi, I have 2 questions: 1. I have an editable data grid with 21 columns. I need to edit only 2 cloumns in this data grid. But when the grid is displayed in Edit mode, all the columns show long text boxes whichmakes the user to SCROLL a lot. I need only these 2 cloumns to be displayed in Edit mode. Is that possible & how? 2. Also, even when the data grid is not displayed in the edit mode, it
14
1842
by: Brett Sinclair | last post by:
Hello everybody I'm still on the learning curve here...and from what I read, I created inherited datagrid class so I could have icons, combobox...etc in the columns of my datagrid. The grid will be used to populate information coming from a Webservice. (No datasets - No datareaders). So, I do not know see how to use the "datasource".
2
2128
by: Billy | last post by:
Change DataGrid EditControl On Data Value Hi, I have a datagrid, and on editing, I want to change the control in the third colunm based on the value of the first column. The value in the first column can only be either "Text" or "Image", which is selcted in a dropdown list.
2
3442
by: Mike Baugh | last post by:
I am using visual studio 2005 to develop a form using c# I have 3 datagrids on one form. I can set the row color based on a certain value in a column. However this color applies to all 3 datagrida. I would like to set it so that if value of column 3 in datagrid 1 is < 100 set to red, if = 100 set to green if value of column 3 in datagrid 2 is < 90 set to red, if >= 90 set to green if value of column 3 in datagrid 3is < 80 set to red,...
0
375
by: rcoco | last post by:
Hi, I have a datagrid that Inserts data into sql datbase, and amongest there is a column that has a radiobuttonlist, the radiobuttonlist contains two radiobuttons one with Good Mood and the otherone with bad moods. In the column I placed two images where one shows a happy face and the other one a sad face and I want when a user selects radiobutton Good Mood the image with a happy face is inserted. but I'm having a problem when I select...
1
2694
by: rascalking | last post by:
Hello, So I've read many forums that explained how to get an image out of SQL Server database and display it. I used an alternate .aspx page to retrieve the image and write it back as binary which everyone on many sites said to do. The problem is its not working. My exact situation is that I am creating News Articles based on news entries which are either text or pictures. I want to display a picture in the datagrid if there is one....
3
1284
by: boyindie86 | last post by:
How can i pull images out of an mysql table and populate the below datagrid. I have all my images stored in an external store, and the addresses are stored in my DB, i am not sure how to pull these addresses out and get it to populate the table. I have the followin ASP code <code><asp:DataGrid runat=server ID=test AllowPaging="True" AutoGenerateColumns="False" CellPadding="4" ForeColor="#333333" GridLines="None" Height="343px" Width="551px">...
0
9619
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9454
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10038
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8934
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7460
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6713
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5354
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3609
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2850
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.