How to set colors to gridview row dynamically.

Posted by Rrana under ASP.NET on 10/20/2011 | Points: 10 | Views : 4039 | Status : [Member] | Replies : 6
Hi,

I have a task that

1. i have a table with the date of colors.
2. i want to retrieve that colors and set that colors to gridview row.


Thanks in advance

Sucharitha Goud
Bank Of America..



Responses

Posted by: Ndebata on: 10/20/2011 [Member] Starter | Points: 25

Up
0
Down
In the row databound event of gridview try to set the background color

Rrana, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Godly77 on: 10/20/2011 [Member] Starter | Points: 25

Up
0
Down
You can apply backcolor to grid row in

    Protected Sub GridView1_RowDataBound(sender As Object, e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound

e.Row.BackColor = Drawing.Color.AliceBlue
End Sub




Godly Mathew

Rrana, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Rrana on: 10/20/2011 [Member] Starter | Points: 25

Up
0
Down
Hi,

Drawing.Color.AliceBlue
is a predifined color right.

MY table

S1 Color

1 Green
2 red
3 Yellow


I need to set the colors dynamically from DB.


Sucharitha Goud
Bank Of America..

Rrana, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ndebata on: 10/20/2011 [Member] Starter | Points: 25

Up
0
Down
Hi
You can use color converter to convert "Red" or "#FF0000"
Please find the attached sample
 Download source file

Rrana, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Jayakumars on: 10/21/2011 [Member] [MVP] Bronze | Points: 25

Up
0
Down
Hi
Ndebata

Why use Override and which purpose use we will go override plz explain them
why use this

protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
GridView1.RowDataBound += new GridViewRowEventHandler(GridView1_RowDataBound);





Mark as Answer if its helpful to you

Rrana, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ndebata on: 10/21/2011 [Member] Starter | Points: 25

Up
0
Down
Hi Jaykumar,

Please read this blog , http://weblogs.asp.net/infinitiesloop/archive/2008/03/24/onload-vs-page-load-vs-load-event.aspx
I hope it can answer your questions.

Thanks,
Debata

Rrana, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response