Go Premium for a chance to win a PS4. Enter to Win

x
?
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
Medium Priority
?
251 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 2000 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

927 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