Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Conditional display of web page element

Reply
Thread Tools

Conditional display of web page element

 
 
Tom Wells
Guest
Posts: n/a
 
      12-27-2004
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?


 
Reply With Quote
 
 
 
 
=?Utf-8?B?UmljaA==?=
Guest
Posts: n/a
 
      12-27-2004
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?
>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Element 'ElephantTreeView' is not a known element. This can occur ifthere is a compilation error in the Web site, or the web.config file ismissing. Options Dave ASP .Net 0 07-05-2010 03:54 PM
how to Update/insert an xml element's text----> (<element>text</element>) HANM XML 2 01-29-2008 03:31 PM
my hide/display function fails when element begins display:none libsfan01 Javascript 5 01-16-2007 10:40 AM
I have one ASP.NET Page. It's for display customer information. Now I want this page to handle the function "Edit" and "Display", Is it possible? Benny Ng ASP .Net 1 01-04-2007 08:00 PM
? ELSE Conditional Comment / Using Conditional Comments Inside Other Tags To Comment Out Attributes Alec S. HTML 10 04-16-2005 02:21 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57