更改GridView行的颜色 [英] changing the gridview row color

查看:72
本文介绍了更改GridView行的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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.....

推荐答案

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



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


这篇关于更改GridView行的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆