473,606 Members | 2,101 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Conditional display of web page element

I have a few things such as buttons and URLs that may or may not be shown
based on the value of a database column. I can hook to the database and get
the dataset and datarecord just fine. I can retrieve the value into a
variable fine. My problem is that I have no idea what code to use to tell a
button not to be displayed if I don't get a certain value. In ASP I would
just embed VBScript to check the value of the variable in an if then and
either include the button or skip it on the fly. I can't seem to figure out
how to do this in ASP.NET.

Would someone please help me out with a code sample or a pointer to where
this is explained?
Nov 19 '05 #1
1 2183
You didn't say whether the controls in question are to be embedded in other
DataBound controls, like a DataGrid, or not.

To start, let's say that you have a button that's not in a grid. If should
not appear on the rendered page when some condition exists, you simplay set
the visible parameter of that control to false (e.g. Button1.visible =False).
When visible is false, the control does not get rendered at all. (It doesn't
even get rendered with display:none.)

Now, it does get a little more involved if you have lots of rows in a
DataGrid, let's say, and a button should appear in some rows and not others.
But this should work:

Use an Item Template in your DataGrid, instead of a bound column. Don't try
to use the Grid Designer to do anything more than add an Item Template and
bind it to a specific column. Any attempt to do anything else with that
thing poses serious risks to your mental health. Once you've set up a
template or two, close the Grid Designer and try to forget that you ever
looked at it. Go into the HTML view and you should see a <Columns> tag with
one or more <asp:TemplateCo lumn> tags contained within it. You should also
see something that looks roughly like this...

<%# DataBinder.Eval (Container.Data Item, "FULLNAME") %>

This expression is what causes the column value for "FULLNAME" to get
rendered into the DataGrid.

You could edit the codeto something like this...

<% If <%# DataBinder.Eval (Container.Data Item, "FULLNAME") %> = "Tom" Then %>
<INPUT Type="Button" Style="..." OnClick="...">
<% End If %>

HTH

"Tom Wells" wrote:
I have a few things such as buttons and URLs that may or may not be shown
based on the value of a database column. I can hook to the database and get
the dataset and datarecord just fine. I can retrieve the value into a
variable fine. My problem is that I have no idea what code to use to tell a
button not to be displayed if I don't get a certain value. In ASP I would
just embed VBScript to check the value of the variable in an if then and
either include the button or skip it on the fly. I can't seem to figure out
how to do this in ASP.NET.

Would someone please help me out with a code sample or a pointer to where
this is explained?

Nov 19 '05 #2

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

Similar topics

8
1866
by: Guy Hocking | last post by:
Hi there, I am having a few problems compiling a list box that is conditional on what is selected in another list box. What i need is a List box (lstArea) that displays one thing when the List Box (lstRegion) is selected East or West. Basically the areas will change when East or West is selected in lstRegion. The data comes from an SQL Server view, and my current non-working code is as follows, my syntax in the SQL statement is...
7
3503
by: Guy Hocking | last post by:
Hi there, I have a problem in my ASP/SQL Server application i am developing, i hope you guys can help. I have a ASP form with list boxes populated by SQL tables. When a user selects a value in a list box and submits the form the value is put into a session variable and the relevant page is displayed (in accordance to one of the list boxes). The page is then displayed with the relevant SQL data. So far i have got the
28
3432
by: Benjamin Niemann | last post by:
Hello, I've been just investigating IE conditional comments - hiding things from non-IE/Win browsers is easy, but I wanted to know, if it's possible to hide code from IE/Win browsers. I found <!> in the original MSDN documentation, but this is (although it is working) unfortunately non-validating gibberish. So I fooled around trying to find a way to make it valid. And voila: <!--><!><!-->
2
5373
by: Piper707 | last post by:
Hi, I need to know if there is any way of achieving conditional processing for XSD elements. --------------------------------------------------------------- <criteria></criteria> = a complex element <join_condition></join_condition> = a simple element --------------------------------------------------------------- EX:
0
7942
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,...
0
8429
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8084
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
8300
tracyyun
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...
0
5461
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
3922
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...
0
3969
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2443
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
1
1550
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.