I was wondering if it is possible to highlight multiple gridview rows depending on the value of a row cell. For example;
There are 10 rows each containing an account number and swiftcode. In 2 rows the Swiftcode is the same so these rows would need to be highlighted. Further down the gridview there are 2 more rows with the same swiftcode (but not the same as the first 2) so
these also need to be highlighted.
So far I have this code - unfortunately it doesnt quite work. Could someone please point me in the right direction?
Thanks for the quick reply. These aren't quite what I was after.
My problem is that I have to iterate through all gridview rows and highlight rows based on whether the rows can be merged because their bank account details are the same. The code I supplied nearly does what I require, unfortunately it only highlights the
matching row further down the gridview not the intial row of the same value.
unfortunately it only highlights the matching row further down the gridview not the intial row of the same value.
Try to put you code on GridView_RowDataBound as:
protected void grdUniqueNames_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
//Here you match your condition as it will loop through for each row.
if (DataBinder.Eval(e.Row.DataItem,"ColumnName") != System.DBNull.Value)
{
e.Row.BackColor = System.Drawing.Color.ForestGreen;
}
}
}
MarkC076
Member
2 Points
2 Posts
Highlighting Multiple GridView Rows
Aug 23, 2011 01:55 PM|LINK
Hi
I was wondering if it is possible to highlight multiple gridview rows depending on the value of a row cell. For example;
There are 10 rows each containing an account number and swiftcode. In 2 rows the Swiftcode is the same so these rows would need to be highlighted. Further down the gridview there are 2 more rows with the same swiftcode (but not the same as the first 2) so these also need to be highlighted.
So far I have this code - unfortunately it doesnt quite work. Could someone please point me in the right direction?
private void GenerateUniqueData(int cellno) {
ColorConverter colConvert = new ColorConverter();
string initialnamevalue = grdUniqueNames.Rows[0].Cells[cellno].Text;
for (int i = 1; i < grdUniqueNames.Rows.Count; i++)
{
if (grdUniqueNames.Rows[i].Cells[cellno].Text == initialnamevalue)
{
grdUniqueNames.Rows[i].BackColor = (System.Drawing.Color)colConvert.ConvertFromString("#666666");
}
else
{
initialnamevalue = grdUniqueNames.Rows[i].Cells[cellno].Text;
}
}
}
Rajneesh Ver...
All-Star
36983 Points
6796 Posts
Re: Highlighting Multiple GridView Rows
Aug 23, 2011 01:57 PM|LINK
see some useful links:
http://www.dotnetcurry.com/ShowArticle.aspx?ID=123
http://social.msdn.microsoft.com/Forums/en-US/winformsdatacontrols/thread/d2395a33-de20-4839-9c35-cca7c17f8b84
www.rajneeshverma.com
Keep Forums Clean || Use Alert Moderators.
MarkC076
Member
2 Points
2 Posts
Re: Highlighting Multiple GridView Rows
Aug 23, 2011 02:08 PM|LINK
Thanks for the quick reply. These aren't quite what I was after.
My problem is that I have to iterate through all gridview rows and highlight rows based on whether the rows can be merged because their bank account details are the same. The code I supplied nearly does what I require, unfortunately it only highlights the matching row further down the gridview not the intial row of the same value.
Rajneesh Ver...
All-Star
36983 Points
6796 Posts
Re: Highlighting Multiple GridView Rows
Aug 23, 2011 02:16 PM|LINK
Try to put you code on GridView_RowDataBound as:
protected void grdUniqueNames_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { //Here you match your condition as it will loop through for each row. if (DataBinder.Eval(e.Row.DataItem,"ColumnName") != System.DBNull.Value) { e.Row.BackColor = System.Drawing.Color.ForestGreen; } } }www.rajneeshverma.com
Keep Forums Clean || Use Alert Moderators.