473,419 Members | 1,689 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,419 software developers and data experts.

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 2171
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:TemplateColumn> tags contained within it. You should also
see something that looks roughly like this...

<%# DataBinder.Eval(Container.DataItem, "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.DataItem, "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
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...
7
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...
28
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...
2
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...
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...
1
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
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...
0
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,...
0
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...

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.