Wrox Programmer Forums
|
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 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 July 22nd, 2005, 01:54 PM
Friend of Wrox
 
Join Date: Jun 2003
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...
 
Old July 22nd, 2005, 02:37 PM
Friend of Wrox
 
Join Date: Jun 2003
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...
 
Old July 25th, 2005, 11:59 PM
Friend of Wrox
 
Join Date: Nov 2003
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.

 
Old July 27th, 2005, 12:40 AM
Registered User
 
Join Date: Jul 2005
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.






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





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