Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If DateTime.Now.Hour > 12 Then
gvPages.ForeColor= Drawing.Color.AliceBlue
Else
gvPages.ForeColor= Drawing.Color.AntiqueWhite
End If
End Sub
I havent been able to get the databound option to works. Infact...my msgbox never even gets displayed....
Protected Sub GridView2_DataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs)
MsgBox("Hi")
If e.Row.RowType = DataControlRowType.DataRow Then
If e.Row.Cells(1).Text = "Job Execution OK" Then
e.Row.Cells(1).ForeColor = Drawing.Color.Red
End If
End If
End Sub
OnRowDataBound isn't working either... not poping the msgbox up or changing color
Protected Sub GridView2_OnRowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs)
MsgBox("Hi")
If e.Row.RowType = DataControlRowType.DataRow Then
If e.Row.Cells(1).Text = "Job Execution OK" Then
e.Row.Cells(1).ForeColor = Drawing.Color.Red
End If
End If
End Sub
darms21
Member
4 Points
65 Posts
Change GridView text color in Page_Load section
Jul 02, 2012 04:03 PM|LINK
Is it possible to change the forecolor of a gridview based on a specific value in the page_load section?
paindaasp
Star
12246 Points
2067 Posts
Re: Change GridView text color in Page_Load section
Jul 02, 2012 04:15 PM|LINK
Do you mean something like this? :
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load If DateTime.Now.Hour > 12 Then gvPages.ForeColor= Drawing.Color.AliceBlue Else gvPages.ForeColor= Drawing.Color.AntiqueWhite End If End Subdarms21
Member
4 Points
65 Posts
Re: Change GridView text color in Page_Load section
Jul 02, 2012 04:17 PM|LINK
Specifically, I want to change the foreclor of a gridview row if the value in that row is like "True" but I want to do it in the page_load section.
rakesh.sawan...
Member
168 Points
173 Posts
Re: Change GridView text color in Page_Load section
Jul 02, 2012 04:19 PM|LINK
<asp:GridView ID="GridView1″ runat="server" AutoGenerateColumns="false" ForeColor="Blue">
<Columns>
<asp:TemplateField HeaderText="ID">
<ItemTemplate>
<asp:Label runat="server" ID="lblNationalID" Text="some text" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
on page_load set forecolor as GridView1.ForeColor = Color.Yellow ;
darms21
Member
4 Points
65 Posts
Re: Change GridView text color in Page_Load section
Jul 02, 2012 04:23 PM|LINK
What exactly would I need to do to my gridview code?
<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource2" Height="97px" AllowSorting="True"> <Columns> <asp:BoundField DataField="Host Name" HeaderText="Host Name" SortExpression="Host Name" > <ItemStyle HorizontalAlign="Left" /> </asp:BoundField> <asp:BoundField DataField="Job Status" HeaderText="Job Status" SortExpression="Job Status" ReadOnly="True" > <ItemStyle HorizontalAlign="Left" /> </asp:BoundField> </Columns> <HeaderStyle Font-Names="Segoe UI" Font-Size="12pt" ForeColor="White" CssClass="tableheader" /> <RowStyle ForeColor="#CCCCCC" /> </asp:GridView>cornball76
Participant
1128 Points
211 Posts
Re: Change GridView text color in Page_Load section
Jul 02, 2012 04:27 PM|LINK
Must it be on the page load? I'm going to guess you are wanting to do it as it binds by looking at whatever value gives you True/False.
You can use the onrowdatabound event of the gridview to inspect row by row and set the color to whatever you want of that row.
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.onrowdatabound.aspx
darms21
Member
4 Points
65 Posts
Re: Change GridView text color in Page_Load section
Jul 02, 2012 04:29 PM|LINK
I havent been able to get the databound option to works. Infact...my msgbox never even gets displayed....
Protected Sub GridView2_DataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs) MsgBox("Hi") If e.Row.RowType = DataControlRowType.DataRow Then If e.Row.Cells(1).Text = "Job Execution OK" Then e.Row.Cells(1).ForeColor = Drawing.Color.Red End If End If End Subcornball76
Participant
1128 Points
211 Posts
Re: Change GridView text color in Page_Load section
Jul 02, 2012 04:33 PM|LINK
Re-read my other post.. DataBound isn't what you are after.
darms21
Member
4 Points
65 Posts
Re: Change GridView text color in Page_Load section
Jul 02, 2012 04:36 PM|LINK
OnRowDataBound isn't working either... not poping the msgbox up or changing color
Protected Sub GridView2_OnRowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs) MsgBox("Hi") If e.Row.RowType = DataControlRowType.DataRow Then If e.Row.Cells(1).Text = "Job Execution OK" Then e.Row.Cells(1).ForeColor = Drawing.Color.Red End If End If End Subcornball76
Participant
1128 Points
211 Posts
Re: Change GridView text color in Page_Load section
Jul 02, 2012 04:41 PM|LINK
In your html do you have the following? OnRowDataBound="GridView2_OnRowDataBound"??
<asp:GridView ID="GridView1" runat="server" OnRowDataBound="GridView2_OnRowDataBound"> </asp:GridView>If you set a break point inside that event does it stop?