Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
|
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# 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 June 30th, 2003, 07:17 AM
Authorized User
 
Join Date: Jun 2003
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default Datagrid ItemDataBound Event Problem

Hi all,

I want to change the colour of an item in a datagrid depending on its date. I have found that this event is the right one but the code at bottom of email (extracted from ms-help://MS.VSCC/MS.MSDNVS/vbcon/html/.....)
appears to generate the error

Server Error in /fileupload Application.
--------------------------------------------------------------------------------

Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.


source code in c#



private void DataList1_ItemDataBound(object sender,
                System.Web.UI.WebControls.DataListItemEventArgs e)
            {
                DataRowView drv = (DataRowView)(e.Item.DataItem);
                int quantity = int.Parse(drv.Row["Quantity"].ToString());
                if (quantity < 10)
                {
                    e.Item.BackColor = Color.Red;
                }
            }

P.S. I have of course changed the function from DataGrid to DataList but this must be supported since Visual Studio produces the function definition

Best wishes,
Grahame

Grahame Hambleton
Webmaster / Developer
Saïd Business School
University of Oxford
Saïd Business School
Park End Street
Oxford OX1 1HP
Tel: +44 (0) 1865 288863
Fax: +44 (0) 1865 288805
email: [email protected]
http://www.sbs.ox.ac.uk
__________________
Best wishes,
Grahame

Grahame Hambleton
Webmaster / Developer
Saïd Business School
University of Oxford
Saïd Business School
Park End Street
Oxford OX1 1HP
Tel: +44 (0) 1865 288863
Fax: +44 (0) 1865 288805
email: [email protected]
http://www.sbs.ox.ac.uk
 
Old December 3rd, 2011, 03:10 AM
Registered User
 
Join Date: Dec 2011
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Thumbs up

I had to load my reader into a datatable first, then set the repeater's datasource to the datatable. Then everything worked fine.

Thanks

Please check the link bellow:
http://forums.asp.net/t/1187140.aspx





Similar Threads
Thread Thread Starter Forum Replies Last Post
ItemDataBound to Grid Within Repeater rstelma ASP.NET 2.0 Professional 4 July 9th, 2008 02:45 AM
Confirm in ItemDataBound rstelma ASP.NET 1.0 and 1.1 Basics 3 December 6th, 2006 02:10 AM
Datagrid ItemDataBound column widht eresina ASP.NET 1.0 and 1.1 Basics 0 August 10th, 2005 04:42 AM
DataGrid ItemDataBound Wyatt70 ADO.NET 2 November 22nd, 2004 03:31 PM





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