在DataGrid中,當Mouse移到數據行上時怎樣讓其高亮顯示,並且當Mouse按下時讓其被選定!謝謝

解决方案 »

  1.   

    private void grd_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
    {
    if(e.Item.ItemIndex>=0)
    {
    e.Item.Attributes.Add("onmouseover","color=this.style.backgroundColor;this.style.backgroundColor='#00ccff'");
    e.Item.Attributes.Add("onmouseout","this.style.backgroundColor=color");
    }

    }
      

  2.   

    http://dotnet.aspx.cc/ShowDetail.aspx?id=E5254FD8-252F-457C-F61E-32EE353E8BF2
      

  3.   

    给你个静态的方法:
    <head>
    <script language="JavaScript" src="">
    function a(){
    var obj=window.event.srcElement;
    if(obj.tagName=="TD")
    obj.style.backgroundColor="#FFFFCC";
    }
    function b(){
    var obj=window.event.srcElement;
    if(obj.tagName=="TD")
    obj.style.backgroundColor="";
    }
    </script>
    </head>__________________
    private void Page_Load(object sender, System.EventArgs e)
    {
       this.dataGrid1.Attributes.Add("onmouseover", "a();");
       this.dataGrid1.Attributes.Add("onmouseout", "b();");
    }
      

  4.   

    执行后结果如:
    <script language="JavaScript" src="">
    function a(){
    var obj=window.event.srcElement;
    if(obj.tagName=="TD")
    obj.style.backgroundColor="#FFFFCC";
    }
    function b(){
    var obj=window.event.srcElement;
    if(obj.tagName=="TD")
    obj.style.backgroundColor="";
    }
    </script> <table onmouseover="a();" onmouseout="b();" width="500" cellspacing=0>
    <tr>
    <td height="20" align="center" bgcolor="#EEEEEE">
    </td>
    </tr>
    <tr>
    <td height="20" align="center" bgcolor="#EEEEEE">
    </td>
    </tr>
    <tr>
    <td height="20" align="center" bgcolor="#EEEEEE">
    </td>
    </tr>
    <tr>
    <td height="20" align="center" bgcolor="#EEEEEE">
    </td>
    </tr>
    <tr>
    <td height="20" align="center" bgcolor="#EEEEEE">
    </td>
    </tr>
    <tr>
    <td height="20" align="center" bgcolor="#EEEEEE">
    </td>
    </tr>
    </table>
      

  5.   

    我是使用VB.net的,在 .aspx.vb 中写:    Private Sub grdEventSelection_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles grdEventSelection.ItemDataBound
            If e.Item.Cells(0).Text <> "COE_ID" Then
                Dim Url_Para As String = "clientid=" + GetParameter.GetParameter(mPara, "clientid") + "&eventid=" + e.Item.Cells(0).Text
                Url_Para = GetParameter.CodingString(Url_Para)
                Dim rowID As String = "ip_coe_" & e.Item.Cells(0).Text & Int(100 * Rnd())
                e.Item.Attributes.Add("id", "ID_" + e.Item.Cells(0).Text)
                e.Item.Attributes.Add("onMousedown", "javascript:onfocuscolor(this,'" + e.Item.Cells(0).Text + "','" + rowID + "');")
                e.Item.Cells(2).Text = "<A id='" + rowID + "' target='ip_coe_" + e.Item.Cells(0).Text + "' href='ip_coe_detail.aspx?Para=" + Url_Para + "'>" + e.Item.Cells(2).Text + "</A>"
                If IsDate(e.Item.Cells(4).Text) Then
                    If CDate(e.Item.Cells(4).Text) < Now.Date Then
                        e.Item.Attributes.Add("style", "BACKGROUND-COLOR: inactiveborder")
                    End If
                End If
            End If        e.Item.Attributes.Add("style", "cursor: default")
        End Sub
      

  6.   

    在 .aspx中添加脚本:
    var oldid="";
    var selid="";

    function onfocuscolor(line, eventid,rowID)
    {
    if (oldid == line){
    line.style.backgroundColor = "#ffffff";
    line.style.color = "#003399";
    oldid = "";
    selid = "";
    document.Form1.coeid.value=selid;
    document.Form1.RowID.value="";
    }else{
    if (oldid==""){
    line.style.backgroundColor = "#009999";
    line.style.color = "#CCFF99";
    oldid = line;
    selid = eventid;
    document.Form1.coeid.value=selid;
    document.Form1.RowID.value=rowID;
    }else{
    line.style.backgroundColor = "#009999";
    line.style.color = "#CCFF99";
    oldid.style.backgroundColor = "#ffffff";
    oldid.style.color = "#003399";
    oldid = line;
    selid = eventid;
    document.Form1.coeid.value=selid;
    document.Form1.RowID.value=rowID;
    }
    }
    }