• <ruby id="5koa6"></ruby>
    <ruby id="5koa6"><option id="5koa6"><thead id="5koa6"></thead></option></ruby>

    <progress id="5koa6"></progress>

  • <strong id="5koa6"></strong>
  • 在Web DataGrid中當鼠標移到某行與離開時行的顏色發生改變(結合javascript)

    發表于:2007-06-21來源:作者:點擊數: 標簽:
    在head中添加 java script 代碼如下: script lang=javascript function sel(i) // 鼠標移上去后執行 { eval(i+".style.background='# CC CC66'"); // 更改行的顏色 eval(i+".style.cursor='hand'"); // 鼠標移上去后變為手形 } function unsel(i) // 鼠標離

       

    在head中添加javascript 代碼如下:

    <script lang=javascript>
     function sel(i) // 鼠標移上去后執行
     {
      eval(i+".style.background='#CCCC66'"); // 更改行的顏色

      eval(i+".style.cursor='hand'"); // 鼠標移上去后變為手形
     }
     function unsel(i) // 鼠標離開后執行
     {
      eval(i+".style.background=''");
     }
     function clicktr(i)
     {
      eval(i+".style.background=''");
      window.open("Edit.aspx?param="+i,"修改","height=490,width=710,resizable=no,scrollbars=no,status=no,toolbar=no,
    menubar=no,location=no,left=50,top=50");
     }
    </script>

    在DataGrid的 ItemDataBound (當數據綁定時發生)事件中:

    private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
      {  
       if(e.Item.ItemType != ListItemType.Header)
       {
        string ID = e.Item.Cells[0].Text;     // 這里的第一列為數據綁定中的ID值(為修改頁中傳遞參數方便,若多參數,也可按需要增加!)
        e.Item.Attributes.Add("id",ID);
        e.Item.Attributes.Add("onmouseover","sel(" + ID+ ")");   
        e.Item.Attributes.Add("onmouseout", "unsel(" + ID+ ")");
        e.Item.Attributes.Add("onclick", "clicktr(" + ID+")");
       }
      }


    //****************************     結束    **********************************************//

    不過以上做法存在不便之處,如果在DataGrid中加個模板列,用于給用戶提供選擇操作(比如刪除選中),
    此時用上述方法就會造成每次在選擇CheckBox的時候也彈出新窗口(激發了onclick事件)

    比較差的解決辦法:

    將原先的基于行的 Attributes 改為基于列.除掉模板列外,所有列都添加屬性.

    比如模板列在第6列,可以這樣修改 cs 文件

    private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
      {  
       if(e.Item.ItemType != ListItemType.Header)
       {
        string bm = e.Item.Cells[0].Text;
        for(int i=0;i<5;i++)
        {
         e.Item.Cells[i].Attributes.Add("id","a"+i.ToString()+bm);
         e.Item.Cells[i].Attributes.Add("onmouseover","sel(" +i.ToString()+","+ bm + ")");   
         e.Item.Cells[i].Attributes.Add("onmouseout", "unsel(" +i.ToString()+","+ bm + ")");
         e.Item.Cells[i].Attributes.Add("onclick", "clicktr(" + bm +")");
        }
     }
    }


    在 javascript 代碼中:

     function sel(i,ID)
     {
      for(var j=0;j<5;j++)
      { eval("a"+j.toString()+ID+".style.background='#CCCC66'"); eval("a"+j.toString()+ID+".style.cursor='hand'");
      }
    }
    function unsel(i,ID)
    {
       for(var j=0;j<5;j++)
      { eval("a"+j.toString()+ID+".style.background=''");
     }
    }
    function clicktr(i)
    {
      for(var j=0;j<5;j++)
      {
        eval("a"+j.toString()+i+".style.background=''");
        window.open("Edit.aspx?param="+i,"修改","height=490,width=710,resizable=no,scrollbars=no,status=no,toolbar=no,
    menubar=no,location=no,left=50,top=50");
     }

      }

    原文轉自:http://www.kjueaiud.com

    老湿亚洲永久精品ww47香蕉图片_日韩欧美中文字幕北美法律_国产AV永久无码天堂影院_久久婷婷综合色丁香五月

  • <ruby id="5koa6"></ruby>
    <ruby id="5koa6"><option id="5koa6"><thead id="5koa6"></thead></option></ruby>

    <progress id="5koa6"></progress>

  • <strong id="5koa6"></strong>