954,580 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Changing the cell color by clicking on the cell in gridview

Hi Folks,
I have created one gridview.In that gridview i've placed buttons in every cells.My task here is...when i click the button automatically that particular cell color should get changed.I even used code using system.drawing.color on selected index changing event.But once i click any one cell it affects all the cell.For your reference iam sending you my sample code can you please help me out with this.

On SelectedIndexChanging()
{
GridView1.Rows[0].Cells[0].BackColor = System.Drawing.Color.WhiteSmoke;
        GridView1.Rows[0].Cells[1].BackColor = System.Drawing.Color.Beige;
        GridView1.Rows[0].Cells[2].BackColor = System.Drawing.Color.Tomato;
        GridView1.Rows[1].Cells[0].BackColor = System.Drawing.Color.CadetBlue;
        GridView1.Rows[1].Cells[1].BackColor = System.Drawing.Color.DarkOliveGreen;
        GridView1.Rows[1].Cells[2].BackColor = System.Drawing.Color.DarkSlateGray;
        GridView1.Rows[2].Cells[0].BackColor = System.Drawing.Color.ForestGreen;
        GridView1.Rows[2].Cells[1].BackColor = System.Drawing.Color.CornflowerBlue;
        GridView1.Rows[2].Cells[2].BackColor = System.Drawing.Color.Cornsilk;
}


Kindly check the code and help me out with this task.


Thanks and Regards,
Leo franklin.M

lefrancisco1
Newbie Poster
4 posts since Mar 2009
Reputation Points: 10
Solved Threads: 0
 

Good Afternoon lefrancisco1

You are using the Wrong event

use

protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
    {

    }



Hope it Helps


Vuyiswa Maseko

vuyiswamb
Posting Whiz
312 posts since Mar 2007
Reputation Points: 31
Solved Threads: 14
 

Read about Event-Bubbling. It's prime concept to handle events for child controls.

__avd
Posting Genius (adatapost)
Moderator
8,648 posts since Oct 2008
Reputation Points: 2,136
Solved Threads: 1,241
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You