469,944 Members | 2,326 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,944 developers. It's quick & easy.

How to color in gridview

I have gridview in asp.net ( c# ) , and i have to column in gridview 1st column it's a number and 2nd column it's a color , and I use SQL server database and I used sqldatasource in asp.net .. The question ?

I wont the color in 2nd column depending the value from database ,since
I saved in the database color name for example :

1 red
2 black
3 blue
4 green

I wont the color in gridview without color name ?

please I wont the answer ... Thanks & best my regards for all
Apr 12 '10 #1

✓ answered by yarbrough40


4 2158
Thank u MR,Yarbrough40 for answer

But, I want another answer

details

I used SQL server database and I have table from two column 1st field typed number and 2nd field typed varchar2(50) and I am saved in the 2nd field color name
for example

1st field 2nd field
1 red
2 green
3 blue

and so on.

I wont in the gridview when I display database in the grid view the fisrt column I displayed number there's no problem , and second column I wont display the color no display color name in the gridview (ASP.net C#)

for since
I am inserted to the database from ExtcolorDropDownlist

please Help me and the best with my regards

abulaziz68
Apr 13 '10 #3
liawcv
33
Try if the GridView's RowDataBound event can fulfill your requirement:

- Assume the GridView is named "GridView1" and the field contains the color names is named "Color". I would like to display the color in the 2nd cell (with index 1)...

Expand|Select|Wrap|Line Numbers
  1. protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
  2. {
  3.     if (e.Row.RowType == DataControlRowType.DataRow)
  4.     {
  5.         DataRowView drv = (DataRowView)e.Row.DataItem;
  6.         e.Row.Cells[1].BackColor = Color.FromName((string)drv["Color"]);
  7.     }
  8. }
  9.  
- System.Data and System.Drawing name spaces should be imported.
Apr 13 '10 #4
tlhintoq
3,525 Expert 2GB
abdulaziz68: Please do not start no threads to answer existing questions. Keep all responses to the one thread. Your new thread has been merged into this original question.
Apr 13 '10 #5

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

5 posts views Thread by sutphinwb | last post: by
1 post views Thread by joechipubik | last post: by
3 posts views Thread by Jeff | last post: by
2 posts views Thread by antonyliu2002 | last post: by
5 posts views Thread by Andrew Robinson | last post: by
3 posts views Thread by Peter | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.