Solved

Comparing the values of two columns in a datagrid and manipulating the data in the columns as a result

Posted on 2006-11-16
5
227 Views
Last Modified: 2010-04-16
Hi,

I'm populating a datagrid from a database and two of the columns that are populated are a debit and credit values. For each row in the datagrid I want to compare the debit and credit columns' values. If the values are not the same, I want the debit and credit values to be displayed in red in the datagrid.

Any help would be appreciated.

Thanks!
0
Comment
Question by:GlobexCorp
  • 2
  • 2
5 Comments
 
LVL 29

Expert Comment

by:Gautham Janardhan
Comment Utility
what sort of grid are u using normal windows grid ?
0
 
LVL 2

Author Comment

by:GlobexCorp
Comment Utility
It's a webcontrol grid
0
 
LVL 13

Accepted Solution

by:
newyuppie earned 500 total points
Comment Utility
i found this example in codeproject: http://www.codeproject.com/aspnet/gridcolumnformatting.asp


this.DataGrid1.ItemDataBound += new System.Web.UI.WebControls.DataGridItemEventHandler(this.OnNWDataBound);

private void OnNWDataBound(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;
        // Get fourth column value.
        Int32 nUnitsInStock = Convert.ToInt32(rv.Row.ItemArray[4]);
        if (nUnitsInStock < 20)
        {
           e.Item.Cells[4].BackColor = Color.Red;
        }
    }
}

it shows how to get values from a column, how to change background color, etc. it just needs a little modification. hoep it helps a bit
NY

0
 
LVL 2

Author Comment

by:GlobexCorp
Comment Utility
Thanks newyuppie!
0
 
LVL 13

Expert Comment

by:newyuppie
Comment Utility
sure, thanks for the points!
NY
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Article by: Ivo
Anonymous Types in C# by Ivo Stoykov Anonymous Types are useful when  we do not need to follow usual work-flow -- creating object of some type, assign some read-only values and then doing something with them. Instead we can encapsulate this read…
Introduction                                                 Was the var keyword really only brought out to shorten your syntax? Or have the VB language guys got their way in C#? What type of variable is it? All will be revealed.   Also called…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now