protected void DataGrid1_ItemDataBound(object sender, DataGridItemEventArgs e)
    {
        if (e.Item.ItemType == DataControlRowType.DataRow)
        {
            e.Item.Attributes.Add("onclick", "if(document.oldTr !=null){document.oldTr.runtimeStyle.cssText='';}this.runtimeStyle.cssText='background-color:red';document.oldTr=this;window.showModelessDialog('bb.aspx?id=" + e.Row.Cells[0].Text + "');");
        }
    }

解决方案 »

  1.   

    写的好深啊,没看懂. 就看懂了 要设置datagrid控件要利用控件的 ItemDataBound事件.
    下面的代码:e.Item.ItemType  , DataControlRowType.DataRow 都是什么意思? 
    {document.oldTr.runtimeStyle.cssText='';}this.runtimeStyle.cssText='background-color:red';document.oldTr=this;window.showModelessDialog('bb.aspx?id=" + e.Row.Cells[0].Text + "');"); 
    这是html代码?  怎么还有什么css的... 就改变个颜色,需要这么复杂吗?
      

  2.   

    1。为你的DataGrid添加一个选择列,然后,只要点那个 选择列,改行就变色,选择列在DataGrid的属性生成器中可以添加,添加后,对选择列的 样式进行设置,如选中的颜色等等,如果没有设置,可能没有效果
      

  3.   

    2。鼠标在某行之上时颜色反选在ItemDataBound事件中添加如下代码
    //反选效果
    if(e.Item.ItemIndex>=0)
    {
    e.Item.Attributes.Add("onmouseover", "curr=this.style.backgroundColor;this.style.backgroundColor='#ffff99'");
    e.Item.Attributes.Add("onMouseOut", "this.style.backgroundColor=curr");
    }
      

  4.   

    关于点击变色,在DataGrid的 属性生成器中,找到“列”-》按钮列-》选择列,然后添加。再再属性生成器中找到“格式”项,选中“项”-》选定项,然后设定背景色,再运行就可看到效果
      

  5.   

    Click the link to solve your problem.Good luck!