I have a datagrid control, In that there was few rows like below
| Date | Scanned A | Scanned B | Scanned C |
| 12/12/2013 | 12 | 13 | 14 |
| Subtotal | 12 | 13 | 14 |
| 07/08/2014 | 12 | 13 | 15 |
| 07/08/2014 | 12 | 13 | 15 |
| Subtotal | 24 | 26 | 30 |
| Total | 36 | 39 | 44 |
Here I need to highlight the sub total row. Font style = Bold and background color to differentiate from other rows.
Can we achieve this using DataGrid1_ItemDataBound event. If yes please post solution using DataGrid1_ItemDataBound event.
Thanks in Advance
Abhishek KumarPosted Aug 27, 2014, 9:40 AM
Please try using the below code.
protected void highlightrow(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
string TotalRow = e.Row.Cells[2].Text;
if (TotalRow == "Total")
{
e.Row.BackColor = Color.Red;
}
}
}
Abhishek
Rajkumar RPosted Aug 27, 2014, 9:38 AM
Rishikesh Kumar SinghPosted Aug 27, 2014, 8:11 AM
private void dataGridView1_RowPrePaint(object sender, DataGridViewRowPrePaintEventArgs e)
{
if (dataGridView1["Date", e.RowIndex].Value.ToString() == "Subtotal")
{
dataGridView1.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.Yellow;
dataGridView1.Rows[e.RowIndex].DefaultCellStyle.Font.Bold = true;
}
}
Use above snippet..!!
mark it as accepted if it helps you..!!
Rajkumar RPosted Aug 27, 2014, 3:59 AM
Dipankar BiswasPosted Aug 27, 2014, 2:37 AM