473,473 Members | 4,176 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

ASP.NET Conditional Statements

I have an ASP.NET page that uses a FormView and SqlDataSource. Within my
page I want to change a string if a column within my database record is a
certain value. Here is some sample code:

<asp:Content ID="Content2" ContentPlaceHolderID="Main" Runat="Server">
<asp:FormView ID="FormView1" runat="server" Width="123px"
DataKeyNames="property_key" DataSourceID="SqlDataSource1">
<ItemTemplate>
<strong style="font-size: 12px">For Sale</strong>
</ItemTemplate>
</asp:FormView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$
ConnectionStrings:MyDatabase %>"
SelectCommand="SELECT * from property_info WHERE property_key =
@property_key">
<SelectParameters>
<asp:QueryStringParameter DefaultValue="0" Name="property_key"
QueryStringField="id"
Type="String" />
</SelectParameters>
</asp:SqlDataSource>
</asp:Content>

I know how to use "Eval" to display values from the current database record
but I want to do is change the "For Sale" string to "For Rent" when a
database column is a certain value. I wasn't sure if this would be better
handled with C# code behind - and just use a placeholder or if I should use
code within the page. I'd almost prefer to use a place holder but I'm not
sure how to access to current database record from the C# code behind. Or
if this should be handled within the page, I don't know the syntax to do a
conditional statement here. Ever tried searching MSDN for "conditional
statement ASP.NET"? :-) Please excuse my ignorance but I haven't done much
ASP.NET work.

Any suggestions would be greatly appreciated.

TIA

Brian

Jul 20 '07 #1
1 2569
JC
You could use a SQL case statement and return the correct value from the
database.

"Brian" <br************@ishcm.comwrote in message
news:DD**********************************@microsof t.com...
>I have an ASP.NET page that uses a FormView and SqlDataSource. Within my
page I want to change a string if a column within my database record is a
certain value. Here is some sample code:

<asp:Content ID="Content2" ContentPlaceHolderID="Main" Runat="Server">
<asp:FormView ID="FormView1" runat="server" Width="123px"
DataKeyNames="property_key" DataSourceID="SqlDataSource1">
<ItemTemplate>
<strong style="font-size: 12px">For Sale</strong>
</ItemTemplate>
</asp:FormView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:MyDatabase %>"
SelectCommand="SELECT * from property_info WHERE property_key =
@property_key">
<SelectParameters>
<asp:QueryStringParameter DefaultValue="0" Name="property_key"
QueryStringField="id"
Type="String" />
</SelectParameters>
</asp:SqlDataSource>
</asp:Content>

I know how to use "Eval" to display values from the current database
record but I want to do is change the "For Sale" string to "For Rent" when
a database column is a certain value. I wasn't sure if this would be
better handled with C# code behind - and just use a placeholder or if I
should use code within the page. I'd almost prefer to use a place holder
but I'm not sure how to access to current database record from the C# code
behind. Or if this should be handled within the page, I don't know the
syntax to do a conditional statement here. Ever tried searching MSDN for
"conditional statement ASP.NET"? :-) Please excuse my ignorance but I
haven't done much ASP.NET work.

Any suggestions would be greatly appreciated.

TIA

Brian

Jul 20 '07 #2

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

Similar topics

15
by: Max | last post by:
Hi, I'm a perl programmer and am trying to learn PHP. So far I have figured out most of the differences, but have not been able to find out how to do the following: When running through a...
8
by: neblackcat | last post by:
Would anyone like to comment on the following idea? I was just going to offer it as a new PEP until it was suggested that I post it here for comment & consideration against PEP 308. I'm far...
10
by: clueless_google | last post by:
hello. i've been beating my head against a wall over this for too long. setting the variables 'z' or 'y' to differing numbers, the following 'if/else' code snippet works fine; however, the ...
3
by: Jouke Langhout | last post by:
Hello all! For quite some time now, I've got the following problem: Access won't close properly when a user closes the application. An ACCESS process stays active and that process can only be...
1
by: chris han | last post by:
Hi, all, I'm trying to use Conditional Compilation Statements in my code. using System; #define DEBUG public class MyClass { public static void Main() {
92
by: Raghavendra R A V, CSS India | last post by:
hie.. Do any one knows how to write a C program without using the conditional statements if, for, while, do, switch, goto and even condotional statements ? It would be a great help for me if...
10
by: nimmi_srivastav | last post by:
Below you will see an example of a nested conditional expression that this colleague of mine loves. He claims that it is more efficient that a multi-level if-else-if structure. Moreover, our...
10
by: Dave | last post by:
I'm a C++ programmer of many years, trying to get my feet wet in C#. I have a question about conditional compilation. In C++, I would sometimes define a constant in an include file, and then...
5
by: Gary Wessle | last post by:
Hi I have a group of functions which have the same signature. void fun_n(void); according to a conditional structure "be it if-else or switch-case" I get to choose which one to run. ...
43
by: dev_cool | last post by:
Hello friends, I'm a beginner in C programming. One of my friends asked me to write a program in C.The purpose of the program is print 1 to n without any conditional statement, loop or jump. ...
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
Oralloy
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,...
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...
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,...
1
isladogs
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...
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...
0
muto222
php
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.