How to Change the Cell Color in GridView

Written by jim stewart
  • Share
  • Tweet
  • Share
  • Pin
  • Email
How to Change the Cell Color in GridView
(Thinkstock Images/Comstock/Getty Images)

A gridview is a digital graphic data interface used for presentations and baseline information inputs. Software development platforms such as ASP.NET, VisualBasic, C# and C++ are used to create a gridview. These software development platforms use a programming language called HTML, or Hyper Text Markup Language. HTML uses tags to represent certain degrees of values like colour, width, background, text, size and dimension. You can change the cell colour in gridview by changing the colour tag in HTML.

Skill level:
Moderate

Other People Are Reading

Instructions

  1. 1

    Download the program ASP.NET and save it to a specified location. Make a new ASPX file and name it "Default2.aspx." Create a blank project, then make an "Images" folder. Right click on "Images" and select "Add Existing Item".

  2. 2

    Open your downloaded program and select ".GIF Files" and then click "Add." You will be transferred to a design view window. Add a "Data Source." Organize this "Data Source" to select each of the individual Data Sources.

  3. 3

    Select the Grid View "Smart Tag" and open the "Task List." Allow "Sorting," "Deleting," "Paging" and "Editing" from the field. Then select "Edit Columns."

  4. 4

    Examine the screen and look for the "Command Field" located in the lower right section of the screen. Click it, and it will show all the attributes. Select RowDataBound to configure it manually.

  5. 5

    Change GridView attributes via SqlDataSource by defining concrete attributes such as the product name, production company, orders, dates and other pertinent data points.

  6. 6

    Open the blank project you made. The attributes will then be specified there in the order that you selected, and presented in "cells."

  7. 7

    Click on the RowDataBound on the GridView window, and HTML syntax will appear in this form.

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)

    {

    if (e.Row.RowType == DataControlRowType.DataRow)

    {

    //We're only interested in Rows that contain data
    
    
    
    //get a reference to the data used to databound the row
    
    DataRowView drv = (DataRowView)e.Row.DataItem;
    
    if (Convert.ToInt32(drv["UnitsInStock"]) == 0)
    
    
    
    {
    
    
    
      //The current product has 0 items in stock
    
      e.Row.Font.Bold = true; //Make the font bold
    
      e.Row.ForeColor = System.Drawing.Color.Red; //Set the text color red
    
      if (Convert.ToInt32(drv["UnitsOnOrder"]) > 0)
    
    
    
      {
    
    
    
         //The current out of stock item has already been ordered
    
         //Make it blue
    
         e.Row.ForeColor = System.Drawing.Color.Blue;
    
    
    
      }
    
    
    
    }
    

    }

    }

    To change the color of a certain attribute, locate the small letter "e," look for the word of the color along that line, and change it to your choice of color.

Don't Miss

Filter:
  • All types
  • Articles
  • Slideshows
  • Videos
Sort:
  • Most relevant
  • Most popular
  • Most recent

No articles available

No slideshows available

No videos available

By using the eHow.co.uk site, you consent to the use of cookies. For more information, please see our Cookie policy.