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

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!
LVL 2
GlobexCorpAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
newyuppieConnect With a Mentor Commented:
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
 
Gautham JanardhanCommented:
what sort of grid are u using normal windows grid ?
0
 
GlobexCorpAuthor Commented:
It's a webcontrol grid
0
 
GlobexCorpAuthor Commented:
Thanks newyuppie!
0
 
newyuppieCommented:
sure, thanks for the points!
NY
0
All Courses

From novice to tech pro — start learning today.