You can set the OnDataBound property of a gridview to a subroutine where you can do the checking.
Sub gvHighlight(ByVal s As Object, ByVal e As EventArgs)
For Each gr As GridViewRow In s.Rows
If gr.Cells(1).Text = "Local0.Alert" Then
gr.BackColor = Drawing.Color.Red
End If
Next
End Sub
...
<asp:GridView ID="GridView1" runat="server" OnDataBound="gvHighlight" />
frist44
Member
193 Points
447 Posts
Highlight row in Gridview if column meets condition
Mar 01, 2007 12:48 PM|LINK
Hi, i'm new to this stuff and am trying to figure out how to automatically highlight a row if column meets a certain condition.
I just want the row to change to red if the column with a value of "MsgPriority" equals "Local0.Alert".
help?
Thanks,
Brandon
iglesia777
Member
648 Points
194 Posts
Re: Highlight row in Gridview if column meets condition
Mar 01, 2007 01:53 PM|LINK
You can set the OnDataBound property of a gridview to a subroutine where you can do the checking.
Sub gvHighlight(ByVal s As Object, ByVal e As EventArgs) For Each gr As GridViewRow In s.Rows If gr.Cells(1).Text = "Local0.Alert" Then gr.BackColor = Drawing.Color.Red End If Next End Sub ... <asp:GridView ID="GridView1" runat="server" OnDataBound="gvHighlight" />Don't forget to click "Mark as Answer" on the post that helped you.
frist44
Member
193 Points
447 Posts
Re: Highlight row in Gridview if column meets condition
Mar 01, 2007 03:45 PM|LINK
any possibility you could hit me with the C# code as that's what the pages are in.
this extremely helpful.
thanks,
Brandon
limno
All-Star
117340 Points
8005 Posts
Moderator
MVP
Re: Highlight row in Gridview if column meets condition
Mar 01, 2007 05:10 PM|LINK
You can check your value conditon from OnRowBataBound too:
Format your SQL query with instant sql formatter:
http://www.dpriver.com/pp/sqlformat.htm
frist44
Member
193 Points
447 Posts
Re: Highlight row in Gridview if column meets condition
Mar 01, 2007 07:27 PM|LINK
I'm not much of a programmer, but I'm trying, is there anyway you could give me some help getting my specific variables in there.
thanks,
Brandon
limno
All-Star
117340 Points
8005 Posts
Moderator
MVP
Re: Highlight row in Gridview if column meets condition
Mar 01, 2007 09:24 PM|LINK
protected void GridView1_OnRowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { if (Convert.ToString(DataBinder.Eval(e.Row.DataItem, "MsgPriority")) == "Local0.Alert") { e.Row.BackColor = System.Drawing.Color.Red; } else { e.Row.ForeColor = System.Drawing.Color.Yellow; } } }Format your SQL query with instant sql formatter:
http://www.dpriver.com/pp/sqlformat.htm
frist44
Member
193 Points
447 Posts
Re: Highlight row in Gridview if column meets condition
Mar 02, 2007 12:19 PM|LINK
worked perfect. Thanks for the help!
Brandon
12shree
Member
4 Points
2 Posts
Re: Highlight row in Gridview if column meets condition
Feb 06, 2008 09:24 AM|LINK
It worked perfect thanks for ur help