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
235 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
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…

713 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