Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old May 24th, 2006, 09:59 AM
Authorized User
 
Join Date: Apr 2006
Location: Virginia Beach, VA, USA.
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
Default Embedding HTML in data controls

How can an If/Then statement be embedded in a data control to provide conditional text? I want display the word "Active" in front of the Cat_Key when the value of Cat_Key is less than five. Can <% ASP cdde %> be embedded within the Fields tags to invoke this condition?

<asp:DetailsView ID="DetailsView1" runat="server" AllowPaging="True" AutoGenerateRows="False"
DataKeyNames="Cat_Pkey" DataSourceID="SqlDataSource1" Height="50px" Width="125px">
<Fields>

<-- what to display text "Active" when [Cat_Key] < 5 here -->

<asp:BoundField DataField="Cat_Pkey" HeaderText="Pkey" InsertVisible="False"
                    ReadOnly="True" SortExpression="Cat_Pkey" />
            </Fields>
        </asp:DetailsView>
Reply With Quote
  #2 (permalink)  
Old May 24th, 2006, 10:39 AM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Hi there,

There are a few ways to do this. One is change your database query and give it an additional column that either contains the word active or nothing.

An alternative is to create a TemplateField with a label that is bound to a method in the code behind, like this:
Code:
<asp:TemplateField HeaderText="Description" SortExpression="Description">
  <ItemTemplate>
    <asp:Label ID="Label1" runat="server" Text='<%# 
         GetActiveState(Eval("Description")) %>'></asp:Label>
  </ItemTemplate>
</asp:TemplateField>
The GetActiveState method could look like this:
Quote:
quote: public string GetActiveState(object o)
  {
      return "SomeThing";
  }
  Instead of returning SomeThing you can look at the object o that is passed in, convert it to the proper type (e.g. an int) and then return a relevant text.

Does this help?

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Reply With Quote
  #3 (permalink)  
Old May 24th, 2006, 10:50 AM
Authorized User
 
Join Date: Apr 2006
Location: Virginia Beach, VA, USA.
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you Imar,

I think it helps - I have a long way to go to reasonably understand the mechanics of ASP 2.0 but I have your book instantResults which I will start when I finish the Beginning ASP.NET 2.0.

2.0 is very powerful but the customizing is a little daunting - I am partial to one's and zero's programming, it gives you ultimate control but takes forever and no one, including one's self can later remember how it works. Previewed your book - looks like it will be very helpful and efficient.

Thank you,

Zoltac007
Reply With Quote
  #4 (permalink)  
Old May 24th, 2006, 12:35 PM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Well, have fun with the Instant Results book.

You know where to go when you have any questions about it.... ;)

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
The html rendered by controls... philthy BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 5 October 23rd, 2008 04:23 PM
Couple questions about embedding values into html warhero XSLT 2 July 3rd, 2007 03:06 PM
HTML controls g_vamsi_krish ASP.NET 1.0 and 1.1 Professional 7 January 10th, 2006 02:14 AM
HTML Controls rajanikrishna General .NET 1 November 10th, 2004 11:35 AM



All times are GMT -4. The time now is 05:54 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.