473,385 Members | 1,848 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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 2338
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

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

Similar topics

7
by: | last post by:
Hello, Does anyone have an idea on how I can filter the data in the gridview control that was returned by an sql query? I have a gridview that works fine when I populate it with data. Now I...
5
by: Dick | last post by:
I have a GridView bound to an ObjectDataSource. I have a Button that calls GridView.DataBind. I want the row that is selected before the DataBind to still be selected afterwards. This happens...
5
by: sutphinwb | last post by:
Hi - This could be a simple question. When I relate two tables in a datasetet, how do I get that relation to show up in a GridView? The only way I've done it, is to create a separate table in the...
1
by: joechipubik | last post by:
I have a GridView in a FormView that has as its datasource a DataTable that is stored in the session cache. When I first load the page the GridView is displayed correctly, but on subsequent loads...
3
by: Jeff | last post by:
Hey asp.net 2.0 In the source I posted below, there is a GridView (look at the bottom of the script): <asp:GridView ID="gvwOnline" runat="server"> </asp:GridView> I'm trying to assign a...
2
by: antonyliu2002 | last post by:
I've been googling for some time, and could not find the solution to this problem. I am testing the paging feature of gridview. I have a very simple web form on which the user can select a few...
5
by: Andrew Robinson | last post by:
I am attempting to better automate a Pager Template within a GridView. I am succesfully skinning a Drop Down List withing my control (the DDL is added to my control). I correctly populate the item...
8
by: Jeff | last post by:
ASP.NET 2.0 I'm wondering how to set the color of a visited HyperLinkField (the link text) in a GridView?? Here is the markup of the HyperLinkField I have problems with: <asp:HyperLinkField...
6
by: RobertTheProgrammer | last post by:
Hi folks, Here's a weird problem... I have a nested GridView setup (i.e. a GridView within a GridView), and within the nested GridView I have a DropDownList item which has the...
3
by: Peter | last post by:
I have a GridView which is populated by List<ofObjects> Does anyone have example of how to sort the columns of this GridView? I have found examples without DataSourceControl but these use...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.