protected void GridView1_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
    {
        GridView1.Rows[e.NewSelectedIndex].Attributes.Add("onclick", "OnFocus(   '#000000','#FFFFFF','#FFFFFF','#bcbcbc'   );");
    }这个为什么不行?不用SelectedIndexChanging这个事件么?

解决方案 »

  1.   

    this.dg.ItemDataBound += new System.Web.UI.WebControls.DataGridItemEventHandler(this.dg_ItemDataBound1);protected void dg_ItemDataBound1(object sender, DataGridItemEventArgs e) 

    if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) 

    //颜色交替   
    e.Item.Attributes.Add("onmouseover","this.style.backgroundColor='Gainsboro'"); 
    if(e.Item.ItemType == ListItemType.Item) 

    e.Item.BackColor=System.Drawing.Color.LightCyan;
    e.Item.Attributes.Add("onmouseout", "this.style.backgroundColor='LightCyan'"); 
    }  if(e.Item.ItemType ==ListItemType.AlternatingItem) 

    e.Item.BackColor=System.Drawing.Color.White;
    e.Item.Attributes.Add("onmouseout", "this.style.backgroundColor='White'"); 

    }
    }
      

  2.   

    dg_ItemDataBound1写在这里:private void InitializeComponent()

    this.dg.ItemDataBound += new System.Web.UI.WebControls.DataGridItemEventHandler(this.dg_ItemDataBound1);}
      

  3.   

    #region[GV_Brand行加载事件]
        //GV_Brand行加载事件
        protected void GV_Brand_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                //当鼠标停留时更改背景色
                e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#E6E6FA'");
                //当鼠标移开时还原背景色
                e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c");
                //鼠标双击事件
                e.Row.Attributes.Add("ondblclick", "self.location='Brand_Register.aspx?CNID="
                    + GV_Brand.DataKeys[e.Row.RowIndex].Value.ToString() + "'");            RadioButton rb = (RadioButton)e.Row.FindControl("rd_sort");
                rb.Attributes.Add("onclick", "judge(this)");
            }
        }
        #endregion
      

  4.   

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                e.Row.Attributes.Add("onmouseover", "bcl=this.style.backgroundColor;this.style.backgroundColor='#00ffee'");
                e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=bcl;");
            }
        }
      

  5.   

        protected void GV_Brand_RowDataBound(object sender, GridViewRowEventArgs e) 
        { 
            if (e.Row.RowType == DataControlRowType.DataRow) 
            { 
                //当鼠标停留时更改背景色 
                e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#E6E6FA'"); 
                //当鼠标移开时还原背景色 
                e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c"); 
                //鼠标双击事件 
                e.Row.Attributes.Add("ondblclick", "self.location='Brand_Register.aspx?CNID=" 
                    + GV_Brand.DataKeys[e.Row.RowIndex].Value.ToString() + "'");             RadioButton rb = (RadioButton)e.Row.FindControl("rd_sort"); 
                rb.Attributes.Add("onclick", "judge(this)"); 
            } 
        }