How to color in gridview

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • abdulaziz68
    New Member
    • Apr 2010
    • 2

    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
  • yarbrough40
    Contributor
    • Jun 2009
    • 320

    #2



    -Enjoy!

    Comment

    • abdulaziz68
      New Member
      • Apr 2010
      • 2

      #3
      color gridview from database Please

      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 ExtcolorDropDow nlist

      please Help me and the best with my regards

      abulaziz68

      Comment

      • liawcv
        New Member
        • Jan 2009
        • 33

        #4
        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)...

        Code:
        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                DataRowView drv = (DataRowView)e.Row.DataItem;
                e.Row.Cells[1].BackColor = Color.FromName((string)drv["Color"]);
            }
        }
        - System.Data and System.Drawing name spaces should be imported.

        Comment

        • tlhintoq
          Recognized Expert Specialist
          • Mar 2008
          • 3532

          #5
          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.

          Comment

          Working...