Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read

Sponsored Links



Change Color of a cell of Gridview control in Asp.Net

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 17-01-2009
Member
 
Join Date: Dec 2008
Posts: 9
Change Color of a cell of Gridview control in Asp.Net
  

Hi,

I want to change the cell color in gridview in my asp.net project. but i don't know how to change the color in runtime.

If you have any idea about this please help me.

Reply With Quote
  #2  
Old 17-01-2009
Member
 
Join Date: Feb 2008
Posts: 1,843
Re: Change Color of a cell of Gridview control in Asp.Net

In RowDataBound event of GridView, you can do that.

use this code,

Code:
  protected void GridView2_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Cells[0].BackColor = System.Drawing.Color.Gray;
        }
    }
Same can do with datagrid in Item databound event.

Hope this helps you.
Reply With Quote
  #3  
Old 17-01-2009
Member
 
Join Date: Jan 2008
Posts: 1,511
Re: Change Color of a cell of Gridview control in Asp.Net

You can use a template or you can handle the rowdatabound event. if you handle the event, you can simply change the background of the cell with code similar to this one:

void Handle( object sender, GriViewRowEventArgs args )
{
args.Row.Cells[put the position of the cell here].BackColor = your color here;
}
Reply With Quote
  #4  
Old 17-01-2009
Member
 
Join Date: May 2008
Posts: 2,004
Re: Change Color of a cell of Gridview control in Asp.Net

You can refer to http://msdn.microsoft.com/en-us/library/aa479342.aspx for more information about gridview control.
Reply With Quote
  #5  
Old 17-01-2009
Member
 
Join Date: Apr 2008
Posts: 1,997
Re: Change Color of a cell of Gridview control in Asp.Net

If you want to change the color of selected row or cell then,
try the below one...

Code:
Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.SelectedIndexChanged
        
      GridView1.SelectedRow.Cells(4).BackColor = Drawing.Color.Red

End Sub
Reply With Quote
  #6  
Old 16-12-2010
Member
 
Join Date: Dec 2010
Posts: 1
Re: Change Color of a cell of Gridview control in Asp.Net

Useful Materials. They works for me. Thanks a lot
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Change Color of a cell of Gridview control in Asp.Net"
Thread Thread Starter Forum Replies Last Post
Is there any option to change the color of friend/foe to help color blinds play Birds of Steel? I M Perfect Video Games 3 18-03-2012 07:33 PM
Does it is possible to have color shading in a Count if cell Rounder1 MS Office Support 2 16-02-2012 05:37 PM
How to change cell color in excel based on text input Chini mao Windows Software 2 06-01-2012 08:19 PM
How to put background color for html cell Preetish Software Development 3 07-08-2009 03:32 PM
Excel 2000 - Change Default Cell Fill Color Cris Han MS Office Support 2 20-02-2008 08:29 PM


All times are GMT +5.5. The time now is 08:52 PM.