Click here to Skip to main content
15,880,891 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            

            if (e.Row.RowType == DataControlRowType.DataRow)
            {
 e.Row.Attributes.Add("onclick", "this.originalstyle=this.style.backgroundColor;this.style.backgroundColor='#EEFF00'");
                   
           }
           
        }



im able to change the color of the cell row but if i click again i must be able to get the default color... i tried with session variable but its not working. the code is given below...

C#
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
string FromName = Convert.ToString(System.Drawing.Color.Yellow);

 if (GridView1.SelectedRow != null) //not the first row selected
                {
                   
                    if (Session[GridView1.SelectedRow.RowIndex.ToString()] != null) //Session was set
                    {

                        GridView1.SelectedRow.BackColor = System.Drawing.Color.FromName(Session[GridView1.SelectedRow.RowIndex.ToString()].ToString());

}
}
}
please help with this problem.....
Posted
Updated 8-Mar-12 2:51am
v2
Comments
Herman<T>.Instance 8-Mar-12 8:52am    
create a javascript function that can determine the current color.

1 solution

C#
GridView1.RowDataBound += new GridViewRowEventHandler(GridView1_RowDataBound);
	 
	void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
	{
	    if (e.Row.RowType == DataControlRowType.DataRow)
	    {
	        int value = (int)DataBinder.Eval(e.Row.DataItem, e.Row.Cells[2].Text);
	        // e.Row.Cells[2] references the cell value you want to use
	            e.Row.Cells[2].BackColor = Color.FromName("#c6efce");


	    }
	}


http://blog.devexperience.net/en/5/Change_background_color_of_GridView%27s_Rows.aspx[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900