protected void gridview1_RowDataBound(object sender, GridViewRowEventArgs e)
{ if (e.Row.RowType == DataControlRowType.DataRow)
{
if ((selectrow.Value != "") && e.Row.DataItemIndex == Convert.ToInt16(selectrow.Value))
{
e.Row.BackColor = System.Drawing.Color.FromArgb(43519);
}
e.Row.Attributes.Add("onfocusin", "this.style.backgroundColor='#00A9FF'");
e.Row.Attributes.Add("onfocusout", "this.style.backgroundColor='#ffffff'");
}
}问题在于刷新后,原来的被选中行的颜色去不掉了,需要点击原来的选中行,再点出来(触发onfocusout事件)才可以去掉颜色,请教更好的方法,实现这样的功能,务必给出代码
if ((selectrow.Value != "") && e.Row.DataItemIndex == Convert.ToInt16(selectrow.Value))
{
e.Row.BackColor = System.Drawing.Color.FromArgb(43519);
}应该是这里出了问题,去掉这个判断,就能实现你的功能!
{
e.Row.BackColor = System.Drawing.Color.FromName("#00A9FF");
}
Session。不知道,有没有方法。
还是Session记录一下选择的状态!读Session值!操作完还得及时的清空Session!
直接在 GridView1_SelectedIndexChanged事件中操作就行了:
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
GridView1.SelectedRowStyle.BackColor = System.Drawing.Color.FromArgb(43519);
}