Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 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
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old July 22nd, 2005, 01:54 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , USA.
Posts: 100
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to ~Bean~
Default Datagrid Conditional

In my datagrid I have a bound column that display a boolean (1 or 0) value. Instead of the "1" or "0" I want it to display "Yes" or "No"...

how can I do this?

I thought of using a stored procedure with an "If" statement but I really don't know the slightest thing about sp's...



-------------------------
Beware of programmers with screwdrivers...
__________________
-------------------------
Beware of programmers with screwdrivers...
  #2 (permalink)  
Old July 22nd, 2005, 02:37 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , USA.
Posts: 100
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to ~Bean~
Default

Dunno if there's a better way to do this, and I can't believe it but I solved this one myself using a sp...

I created the sp like so,
Code:
CREATE PROCEDURE dbo.sp_Examples

AS
    SELECT DISTINCT id, Name, Active, "ActiveText"=
    CASE WHEN Active = 0 THEN    
        "No"
    WHEN Active = 1 THEN
        "Yes"
    END
    FROM tblExamples 
    RETURN
GO
then just referenced the field ActiveText in my datagrid bound column...

sweet...


-------------------------
Beware of programmers with screwdrivers...
  #3 (permalink)  
Old July 25th, 2005, 11:59 PM
Friend of Wrox
Points: 4,332, Level: 27
Points: 4,332, Level: 27 Points: 4,332, Level: 27 Points: 4,332, Level: 27
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2003
Location: , NJ, USA.
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

Assuming that your column is defined as a bit, you can use this in the datagrids ItemDataBound Event:

        If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
            If CBool(e.Item.Cells(1).Text) = 0 Then
                e.Item.Cells(1).Text = "No"
            Else
                e.Item.Cells(1).Text = "Yes"
            End If
        End If

However, I suggest your keep your solution as is in the SP.

  #4 (permalink)  
Old July 27th, 2005, 12:40 AM
Registered User
 
Join Date: Jul 2005
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to chambrick Send a message via Yahoo to chambrick
Default

Cool.

Good for you.

I think doing it on the SQL side will offer more efficient processing time.

 


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
conditional IF roy_mm Reporting Services 0 October 30th, 2006 07:52 AM
Conditional Formatting Corey Access 1 November 8th, 2005 12:18 AM
Conditional Validation in a DataGrid acorbo ASP.NET 1.0 and 1.1 Professional 0 August 24th, 2004 01:12 PM
C# Conditional statements sporkman43 General .NET 2 July 23rd, 2004 09:10 AM



All times are GMT -4. The time now is 09:47 AM.


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