Beginner problem with IF statements

K

Karen

Hi,

I'm just working on my first ASP.net site, and I'm having some problems.
In standard ASP I can easily display output based on whether any content
exists for the database field I'm displaying, but I can't seem to work
out how to do the same thing in ASP.net.

What I'm trying to do is display the content of a Dataset if it doesn't
match a particular value. I have a NavName Dataset, which contains the
name of the section of the site the user is in. If the name of the
section is Home, I don't want the name displayed. In classic ASP I'd
use:

<% if DSNavName.FieldValue("Navname") <> "home" then
response.write "<h1>"
response.write DSNavName.FieldValue("Navname")
response.write "</h1>"
end if %>

But if I try to use a varient on this I get an error message. Do I need
to put this into an "asp:" type block?

Sorry if this seems a really basic question!

Karen
 
J

John Timney \(ASP.NET MVP\)

This is where the bound controls actually start being really useful. There
are lots of ways to manage the data once you have it in a dataset.

This example show how to split the data based on a condition using something
called a Rowfilter.

http://authors.aspalliance.com/aldotnet/examples/rowfilterdoublegrid.aspx

Also, using a template column in a bound control like a datagrid allows you
to pass each value through a method (a function) that returns a new or
modified value, thus the example above could be filtered further.

<itemtemplate>
<span><%#
myCustomMethod(Container.DataItem("PersonGender")) %></span>
</itemtemplate>

If you want to do it he old fashioned way, and format the output completely
on your own then you can iterate the dataset using foreach as shown in this
excellent example here

http://authors.aspalliance.com/aspxtreme/adonet/adonetprimer.aspx?pageno=8


Regards

John Timney
ASP.NET MVP
Microsoft Regional Director
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top