I am trying to hide an image in a formview if the imageurl is blank.
Site is driven by database - and if there is nothing in the database as a picture filename then I want to hide the image - If there is a filename in the database I want to show the image.
Showing is not a problem - but I dont want to show an empty placeholder box on the website if there is no file to display.
Tried various methods to no avail.
C# would be ideal as all my other code in C#
Thanks in advance
Code is below -
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
-
ConnectionString="<%$ ConnectionStrings:qbConnectionString %>"
-
SelectCommand="SELECT * FROM [tbl_PageInfo] WHERE ([type] = @type)">
-
<SelectParameters>
-
<asp:QueryStringParameter Name="type" QueryStringField="pageid" />
-
</SelectParameters>
-
</asp:SqlDataSource>
-
-
<asp:FormView ID="FormView2" runat="server" DataSourceID="SqlDataSource1">
-
<ItemTemplate>
-
<asp:Image runat="server"
-
ID="titleimage"
-
ImageUrl='<%#Eval("picturefilename","http://bytes.com/images/{0}") %>'
-
alt='<%# Eval("para1title") %>' Width="200" Height="140" />
-
...
-
..
-
</ItemTemplate>
-
</asp:FormView>
6 17668
put this in the Page Load Event -
if(Image1.ImageUrl == "")
-
{Image1.Visible = false;}
If your added another filter to the select statment in SqlDataSource1, you'd have an easier time.
SELECT * FROM [tbl_PageInfo] WHERE ([type] = @type) AND ([picturefilename] > '')
This way, empty picturefilename rows from the database don't end up in the data source you're binding to, so empty frames won't get displayed.
Another suggestion would be that instead of
SELECT *
try
SELECT [picturefilename], [para1title], [type]
This can save some headaches down the road (don't ask me how I know).
Frinavale 9,735
Recognized Expert Moderator Expert
From what I remember you can't set the Visible property based on the data that the control is bound to declaritively (you could do this perfectly fine if in your C# or VB.NET server code).
I might be wrong, so the first thing you should try is setting the Visibility property depending on the data that the control is bound on.
You can use the IIf Function (or the If Operator which short circuits if the first condition is false...unlike the IIf Function) in your binding.
Try this (it may not work): - <asp:FormView ID="FormView2" runat="server" DataSourceID="SqlDataSource1">
-
<ItemTemplate>
-
<asp:Image runat="server"
-
ID="titleimage"
-
ImageUrl='<%#Eval("picturefilename","http://bytes.com/images/{0}") %>'
-
alt='<%# Eval("para1title") %>'
-
Width="200"
-
Height="140"
-
Visible="<%#If(DataBinder.Eval(Container.DataItem,"picturefilename")!="", True, False) %>" />
If that doesn't work you could set the CSS class for the image to a class so that the image is not displayed.
You would have a CSS class that has the following style:
And you would set the Image's CssClass according to the data it's bound to: -
<asp:FormView ID="FormView2" runat="server" DataSourceID="SqlDataSource1">
-
<ItemTemplate>
-
<asp:Image runat="server"
-
ID="titleimage"
-
ImageUrl='<%#Eval("picturefilename","http://bytes.com/images/{0}") %>'
-
alt='<%# Eval("para1title") %>'
-
Width="200"
-
Height="140"
-
CssClass="<%#If(DataBinder.Eval(Container.DataItem,"picturefilename")!="", "","hide")%>" />
-Frinny
Agree with what Frinny suggested. If compare against empty string (i.e. "") doesn't work, you may try to compare it against DBNull. Example: - <asp:Image ID="Image1" runat="server"
-
ImageUrl='<%# Eval("Picture", "~/Folder/{0}") %>'
-
Visible='<%# !(Eval("Picture") is DBNull) %>'
-
/>
Frinavale 9,735
Recognized Expert Moderator Expert
Did you try this code liawcv?
I'm pretty sure that you'll run into a problem when you try to to use binding to set the Visible property of the Image control....but I'm not 100% sure on that so I'm curious. (I guess I should just try it myself and see what happens but maybe the OP will get back to us about what works and what doesn't)
Regardless of whether or not setting the Visible property works, there are tons of ways to get around this problem :)
-Frinny
Hi Frinny. Ya, I dare not post my codes here before I tried it out. It works : )
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: deko |
last post by:
Is there any way to work around the blank space created by hidden divs? I'm
trying to use a relatively postioned divs with show/hide behaviors to
annotate an image. The divs show/hide onMouseOver/onMouseOut but leave a
blank space on the page when hidden (the space where the divs would normally
be). Is it possible to use z-indexing to put regular content where the
hidden divs would be? When I try to do this, the layers don't unhide as...
|
by: Zambien |
last post by:
Hi all,
Here's my problem. I have tables that are using the menu/submenu idea
for hiding rows. This works fine in IE (of course) and does show/hide
correctly in netscape, but as soon as the shown method is called, the
table gets skewed and the presentation of the data on the page goes
horribly wrong. I don't think this is a table issue as I have spent
alot of time staring at this code. Here is the html...
|
by: Shapper |
last post by:
Hello,
I have an image button in a web page.
The default image is ShowPanel.gif.
When the image is clicked I want the panel "myPanel" to become visible
and the image button to change to HidePanel.gif.
When the image is clicked again now the panel becomes invisible and the
|
by: Thomas Satzinger |
last post by:
Hallo.,
i just encounterd a strange thing which i cannot resolve.
I am saving a bitmap created in memory to the asp temp folder (asp.net 2.0)
this works fine, and i don´t want to create an extra folder in my
application, so i don´t need my people giving that folder the asp
permissions.
Ok, my JPG is in the temp folder.
|
by: rockdale |
last post by:
I believe this must be a very sample question.
I have a image dir under myWebsite (myWebSite is the root dir of my web
appl)
I have an ascx file under myWebsite/userControls
in the c# of ascx file, I load a image file using MapPath.
imgSort.ImageUrl = Server.MapPath("Images/sort_asc.gif");
| |
by: |
last post by:
I'm using the DataList and GridView controls, and I am trying to wrap my
head around the problem of conditionally showing or hiding cells/cell
content based on the presence or absence of DB data. I am finding this sort
of problem by far the most annoying part about working with ASP.NET
controls.
What I want is to know how to do three things:
- conditionally show or hide an ImageField +column+ based on whether or not
an the...
|
by: Deere |
last post by:
When I try to take a database field and change it with a function and
return it...it will not display the image. The "Imageurl" does not
convert to "src=" but stays as ImageUrl.
id=Image2 will display ok ..and shows in view source as .......
<img id="gvwExample_ctl07_Image2"
src=".\images\toys\1_16\thumb\t_15511.jpg" style="border-width:0px;" />
|
by: Switch4Mac |
last post by:
Hi,
I want to insert an ad in my MasterPage. So in the MasterPage, I
have this piece of code: <asp:Image ID="GatesAd" runat="server"
ImageUrl="http://www.gate.com/images/banners/gate_148x400_final.gif"
AlternateText="www.Gates.com" />
and I even tried with the simple:
<img src="http://www.gate.com/images/banners/gate_148x400_final.gif"
border="0">
But still, nothing is showing up, anyone has clue about why its not
|
by: smokeyd |
last post by:
i am trying to create a simple image button rollover.. i have
searched this forum and found a number of solutions but none seem to
work. i am just trying to get the onmouseover to swap the image then
restore when rolled out on a web page in vb.net. please can someone
help?
|
by: Samy |
last post by:
Hi There,
I am trying to display images in a gridview and display only valid
images from the html in the database (and not display spacers, 1x1
pixel images etc). For this, I have a gridview with an asp:Image
control in one of its template. I populate the image by setting the
imageurl (remote url) of the image in the rowdatabound event of the
gridview. I have an aspx page called draw.aspx and i do it this way..
imageurl =...
|
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...
| |
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,...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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...
|
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...
|
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();...
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |