Changing color on Boundfield text content
-
Hi. I have this updatepanel, with some fields that are getting filled from an ObjectDataSource. One of the fiels are a date, and i want this date to be marked as red (and maybe in bold) if the date is one day from today or later. Problem is, I have no clue on how to do this, since I am new to asp.net! So is there a way to add a method that changes this specific ItemStyle-ForeColor based on the content i get from my datalayer? This is my updatepanel:
Thanks alot!
-
Hi. I have this updatepanel, with some fields that are getting filled from an ObjectDataSource. One of the fiels are a date, and i want this date to be marked as red (and maybe in bold) if the date is one day from today or later. Problem is, I have no clue on how to do this, since I am new to asp.net! So is there a way to add a method that changes this specific ItemStyle-ForeColor based on the content i get from my datalayer? This is my updatepanel:
Thanks alot!
lvq684 wrote:
I have this updatepanel
It does not matter in your case.
lvq684 wrote:
i want this date to be marked as red (and maybe in bold) if the date is one day from today or later
You need to use RowDataBound of GridView for this.
protected void GridView_RowDataBound(Object sender, GridViewRowEventArgs e)
{
DataControlRowType rtype = e.Row.RowType;
if (rtype == DataControlRowType.DataRow && rtype != DataControlRowType.Footer
&& rtype != DataControlRowType.Separator && rtype != DataControlRowType.Header
&& rtype != DataControlRowType.Pager)
{
//Logic to get the color needed to be shown
Calendar cd = e.Row.FindControl("myCal") as Calendar;
//Set whatever color you need to!
cd.ForeColor = Color.Red;
}
} -
lvq684 wrote:
I have this updatepanel
It does not matter in your case.
lvq684 wrote:
i want this date to be marked as red (and maybe in bold) if the date is one day from today or later
You need to use RowDataBound of GridView for this.
protected void GridView_RowDataBound(Object sender, GridViewRowEventArgs e)
{
DataControlRowType rtype = e.Row.RowType;
if (rtype == DataControlRowType.DataRow && rtype != DataControlRowType.Footer
&& rtype != DataControlRowType.Separator && rtype != DataControlRowType.Header
&& rtype != DataControlRowType.Pager)
{
//Logic to get the color needed to be shown
Calendar cd = e.Row.FindControl("myCal") as Calendar;
//Set whatever color you need to!
cd.ForeColor = Color.Red;
}
} -
Thanks alot for your answer, but I dont quite follow the code. Whats up with the
Calendar cd = e.Row.FindControl("myCal") as Calendar;
And could you please paste the corresponding .aspx code for the Gridview please? I am very grateful!
I believe what i have provided is more than enough.
lvq684 wrote:
could you please paste the corresponding .aspx code
No! i wouldn't
lvq684 wrote:
but I dont quite follow the code
You said you have a calendar inside the grid, so that line gets the calendar control to you. Looks like you are a fresher. Would suggest you to read book first.
-
I believe what i have provided is more than enough.
lvq684 wrote:
could you please paste the corresponding .aspx code
No! i wouldn't
lvq684 wrote:
but I dont quite follow the code
You said you have a calendar inside the grid, so that line gets the calendar control to you. Looks like you are a fresher. Would suggest you to read book first.
Yes, as stated in the first post, I am new to asp.net. It´s not a calendar but a simple string which holds the date. The date sorting is being issued elsewhere. But I´ll try changing the calendar to a string and fiddle with it. Question is just how the page control calls this method. I will google some more. Thanks.