Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP.NET Conditional Statements

Reply
Thread Tools

ASP.NET Conditional Statements

 
 
Brian
Guest
Posts: n/a
 
      07-20-2007
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

 
Reply With Quote
 
 
 
 
JC
Guest
Posts: n/a
 
      07-20-2007
You could use a SQL case statement and return the correct value from the
database.

"Brian" <> wrote in message
newsD5A58C0-EE6C-421D-A1FB-...
>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



 
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
if statements and case statements questions John Crichton Ruby 6 07-12-2010 06:17 PM
Prepare Statements VS Statements Vince Java 12 01-21-2008 01:18 PM
component statements within architecture statements Neil Zanella VHDL 8 10-20-2006 09:05 AM
if statements with or w/o else statements Harry George Python 6 02-23-2004 06:48 PM
Conditional Bean:Define Statements In Struts Cowboy Bob Java 1 01-29-2004 12:14 AM



Advertisments