点击某一模板列,该模板所在的行变色,怎么实现?

解决方案 »

  1.   

    private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
    {

       
    if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) 
     {
    string strcal_Name = (string)DataBinder.Eval(e.Item.DataItem, "Duty");
    ImageButton del = (ImageButton)e.Item.FindControl("del");
    del.Attributes.Add("onclick",String.Format("return confirm('确信要删除该条信息?')",strcal_Name.Trim()));
    if (e.Item.Cells[2].Text.ToLower() != " " && e.Item.Cells[2].Text != "")
    {
    e.Item.Cells[2].Text = publicFunction.getUserName(e.Item.Cells[2].Text,Session);
    } ListItemType itemType = e.Item.ItemType;
    e.Item.Attributes["onmouseover"] = "javascript:this.style.backgroundColor='red';cursor='hand';" ;
    if (itemType == ListItemType.Item )
    {
    e.Item.Attributes["onmouseout"] = "javascript:this.style.backgroundColor='WhiteSmoke';";
    }
    else if( itemType == ListItemType.AlternatingItem)
    {
    e.Item.Attributes["onmouseout"] = "javascript:this.style.backgroundColor='WhiteSmoke';";
    }
     
    }
    这里包含着一个完整的ItemDataBound时间,首先要判断从第2行开始,然后用javasript实现鼠标点到那那就变色,然后在设置单行和双行的颜色变回去。那么颜色也可以用英语写 比如whitesmoke red等等
    问对人了你,我刚研究过这个问题。
      

  2.   

    e.Item.Cells[0].Attributes.Add("onclick", "var tb= this.parentNode;tb.style.backgroundColor='red'"); 
    行,列,全部,根据自己需要改
      

  3.   

    http://community.csdn.net/Expert/topic/3399/3399546.xml?temp=.6452295