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
234 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
ID: 17955425
what sort of grid are u using normal windows grid ?
0
 
LVL 2

Author Comment

by:GlobexCorp
ID: 17955498
It's a webcontrol grid
0
 
LVL 13

Accepted Solution

by:
newyuppie earned 500 total points
ID: 17955597
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
ID: 17955841
Thanks newyuppie!
0
 
LVL 13

Expert Comment

by:newyuppie
ID: 17955863
sure, thanks for the points!
NY
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

825 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