Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 24th, 2006, 09:59 AM
Authorized User
 
Join Date: Apr 2006
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>
 
Old May 24th, 2006, 10:39 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 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
 
Old May 24th, 2006, 10:50 AM
Authorized User
 
Join Date: Apr 2006
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
 
Old May 24th, 2006, 12:35 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 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





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





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