Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / July 2007

Tip: Looking for answers? Try searching our database.

ASP.NET Conditional Statements

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Brian - 20 Jul 2007 02:36 GMT
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
JC - 20 Jul 2007 05:02 GMT
You could use a SQL case statement and return the correct value from the
database.

>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
[quoted text clipped - 35 lines]
>
> Brian

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.