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事件)才可以去掉颜色,请教更好的方法,实现这样的功能,务必给出代码

解决方案 »

  1.   

    干嘛不用onmouseover,onmouseout,非要选中变色? 鼠标放上去变色不也一样么
      

  2.   


    if ((selectrow.Value != "") && e.Row.DataItemIndex == Convert.ToInt16(selectrow.Value))
                    {
                        e.Row.BackColor = System.Drawing.Color.FromArgb(43519);
                     }应该是这里出了问题,去掉这个判断,就能实现你的功能!
      

  3.   

    如果你只是想判断textbox控件中包含的是哪行的数据,就得这么写if (this.selectrow.Text.Contains(e.rows.cells[2].text))
                {
                    e.Row.BackColor = System.Drawing.Color.FromName("#00A9FF");
                }
      

  4.   

    http无状态,要维持状态需要viewstate,最好使用gridview的selecteditemtemplate来设定变色,使用gridview的select事件来选择,不然刷新后是没法保持变色的。
      

  5.   

    这需求又点那个了。。viewstate
    Session。不知道,有没有方法。
      

  6.   

    这个!!???
    还是Session记录一下选择的状态!读Session值!操作完还得及时的清空Session!
      

  7.   

    其实很简单啊
    直接在   GridView1_SelectedIndexChanged事件中操作就行了:
     protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
        {
            GridView1.SelectedRowStyle.BackColor = System.Drawing.Color.FromArgb(43519);
              
                
         }