Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
ASP.NET 1.0 and 1.1 Professional For advanced ASP.NET 1.x coders. Beginning-level questions will be redirected to other forums. NOT for "classic" ASP 3 or the newer ASP.NET 2.0 and 3.5
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Professional 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 March 14th, 2007, 08:19 AM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default Datagrid Item Template question

Hello everyone,
   I am not sure if this is possible, but I am going to ask anyway. I am working with a Databound datagrid and have setup

<columns>
<itemtemplate>
</itemtemplate>
</columns>

for all of the columns in my datagrid. By default I load a CSS Style that is applied to every row and every column in the grid. But now I have the need to change the style of a row if a column holds a certain value. Psuedo code is:

if column value = x
then row style = z
else
row style = default

Does anyone know if this is possible?

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from planoie's profile^^
^^Modified text taken from gbianchi profile^^
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html
================================================== =========
Why can't Programmers, program??
http://www.codinghorror.com/blog/archives/000781.html
================================================== =========
__________________
===============================================
Doug Parsons
Wrox online library: Wrox Books 24 x 7
Did someone here help you? Click on their post!
"Easy is the path to wisdom for those not blinded by themselves."
===============================================
 
Old March 14th, 2007, 08:28 AM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Blah. I hate when the answer to a question is apparent and I over look it. If you need to do conditional formatting to a datagrid, handle the ItemDataBound or ItemCreated event.

Your solution might look something like this:
Code:
        private void dg_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                DataRowView rv = (DataRowView)e.Item.DataItem;
                DateTime dt = Convert.ToDateTime(rv.Row.ItemArray[8]);

                if (DateTime.Compare(DateTime.Now, dt) > 0)
                {
                    for(int i=0; i < e.Item.Cells.Count; i++)
                    {
                        e.Item.Cells[i].CssClass = "lapsedText";
                    }
                }
            }

        }
================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from planoie's profile^^
^^Modified text taken from gbianchi profile^^
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html
================================================== =========
Why can't Programmers, program??
http://www.codinghorror.com/blog/archives/000781.html
================================================== =========
 
Old March 14th, 2007, 09:06 AM
Friend of Wrox
Points: 1,935, Level: 17
Points: 1,935, Level: 17 Points: 1,935, Level: 17 Points: 1,935, Level: 17
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2004
Location: United Kingdom
Posts: 550
Thanks: 0
Thanked 1 Time in 1 Post
Default

Yeah

I too was surprised to see this issue raised by you, but it happens, there's a famous saying "Even Einstein asked questions" . ( I am not comparing you with Einstein) :)

Regards
Mike

Fortune favours the brave, so don't regret on missed oppurtunities.
 
Old March 14th, 2007, 09:08 AM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

I, obviously, haven't had enough coffee yet this morning >< Ahh its going to be one of those days.

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from planoie's profile^^
^^Modified text taken from gbianchi profile^^
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html
================================================== =========
Why can't Programmers, program??
http://www.codinghorror.com/blog/archives/000781.html
================================================== =========




Similar Threads
Thread Thread Starter Forum Replies Last Post
Item Template Query rsm42 ASP.NET 1.0 and 1.1 Basics 0 December 22nd, 2006 07:55 AM
edit item template in a datagrid akshay144 ASP.NET 1.0 and 1.1 Professional 0 October 25th, 2006 05:05 AM
referencing an object in an edit item template dan195 ASP.NET 1.0 and 1.1 Basics 3 September 25th, 2006 07:15 AM
ASP datagrid template textbox question chas036 ASP.NET 1.x and 2.0 Application Design 1 December 29th, 2003 04:01 PM





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