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
239 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

710 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