选取当前行颜色变掉,还想拿第一行,第一列的值.
谁能给点详细点的代码.

解决方案 »

  1.   


    private void DataView1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
    {
    if(e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
    {
    e.Item.Attributes.Add("onclick","return setItemBackColor(this)");
    }
    }JS代码function   setItemBackColor(obj)   
    {   
    var   Curr_TR=document.all.tags("tr");   
    for(var   i=1;i<Curr_TR.length;i++)   
    {   
    if   (Curr_TR[i].style.backgroundColor   =="#ccccff")   
    {   
    Curr_TR[i].style.backgroundColor="white";   
    }   
    }   
    obj.style.backgroundColor="#ccccff";   
    }
      

  2.   

    前台: 
    <script language="javascript"> 
            function doPostBack(a,b) 
            { 
                document.getElementById("div2").innerHTML=a+" <br>"+b; 
            } 
        </script> 后台: 
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) 
        { 
            if (e.Row.RowType == DataControlRowType.DataRow) 
            { 
                e.Row.Attributes.Add("onClick", "javascript:doPostBack('" + e.Row.Cells[0].Text + e.Row.Cells[1].Text + e.Row.Cells[2].Text + "','Select$" + e.Row.RowIndex + "');"); 
            } 
    //e.Row.Cells[0]当前行第一列
    //GridView1.Rows[0].Cells[0].Text  第一行第一列
        }
      

  3.   

    protected void gridvie1_rowdatabound(Object serder,GridViewEventArgs e)
    { //双击事件
        if(e.RowType=DataControlsRowType.DataRow)
         {
               if(e.rows.cells[21].text.ToString().length<=0||e.rows.cells[22].text.Tostring().length<1)
               e.Attributes.Add("onclick","return confirm('不能选取或修改非手动录入记录?');"); }
                e.Attribute.Add("ondblclick","gridview_dbclik("+e.Rows.cells[0]).text.Trim()+","+e.Rows.cells[1].text.Trim()+....+e.Rows.cells[n].text.Trim()+");");
              // e.Attribute.Add("");//添加鼠标样式不记得了
             // GridView1.Rows[i].Attrivutes.Add("ondbclick","window.open('FlowStationEdit.aspx?ID="+ID+"','FS_Left','')");导航至另一个页面
     
         }    
    }
     
    客户端脚本:
    gridview1_dblclick(meterid,recordertime,,,,,,,,,,,,,userid)
    {
       window.document.forms[0].tblPoliceID.value=meterid; window.document.forms[0].Police1.value = recordertime; window.document.forms[0].tblPoliceName.value=userid; window.document.forms[0].tblPoliceMobie.value=PoliceMobie;
          
    }
      

  4.   

    客户端脚本: 
    gridview1_dblclick(meterid,recordertime,,,,,,,,,,,,,userid) 

      window.document.forms[0].tblPoliceID.value=meterid; window.document.forms[0].Police1.value = recordertime; window.document.forms[0].tblPoliceName.value=userid; window.document.forms[0].tblPoliceMobie.value=PoliceMobie; 
         //这个是前台赋值 
    }
      

  5.   

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        //选中行高亮显示
         if (e.Row.RowType == DataControlRowType.DataRow)
         {
             e.Row.Attributes.Add("onmouseover", "currentcolor=this.style.backgroundColor;this.style.backgroundColor='#00bfff'");
             e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=currentcolor");
         }
    }//GridView1.Rows[0].Cells[0].Text  第一行第一列