Click here to Skip to main content
14,661,016 members
Rate this:
Please Sign up or sign in to vote.
See more:
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...

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
digimanus 8-Mar-12 8:52am
   
create a javascript function that can determine the current color.

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

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[^]
   

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100