国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發(fā) > 綜合 > 正文

在 Web DataGrid 中當(dāng)鼠標(biāo)移到某行與離開時行的顏色發(fā)生改變(結(jié)合&#106avascri

2024-07-21 02:15:52
字體:
供稿:網(wǎng)友

在head中添加javascript 代碼如下:

<script lang=javascript>
 function sel(i) // 鼠標(biāo)移上去后執(zhí)行
 {
  eval(i+".style.background='#cccc66'"); // 更改行的顏色
  eval(i+".style.cursor='hand'"); // 鼠標(biāo)移上去后變?yōu)槭中?br> }
 function unsel(i) // 鼠標(biāo)離開后執(zhí)行
 {
  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 (當(dāng)數(shù)據(jù)綁定時發(fā)生)事件中:

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;     // 這里的第一列為數(shù)據(jù)綁定中的id值(為修改頁中傳遞參數(shù)方便,若多參數(shù),也可按需要增加!)
    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+")");
   }
  }



//****************************     結(jié)束    **********************************************//

不過以上做法存在不便之處,如果在datagrid中加個模板列,用于給用戶提供選擇操作(比如刪除選中),
此時用上述方法就會造成每次在選擇checkbox的時候也彈出新窗口(激發(fā)了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");
 }

  }
發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 永和县| 康马县| 乌拉特后旗| 游戏| 大田县| 东源县| 平昌县| 晋江市| 淮南市| 林芝县| 白玉县| 三穗县| 晴隆县| 渭南市| 河北省| 南木林县| 蒙山县| 石城县| 博客| 兴业县| 瑞金市| 富顺县| 长治县| 吴川市| 宁武县| 开平市| 万州区| 马山县| 奎屯市| 循化| 东宁县| 宝丰县| 南昌市| 余江县| 鸡泽县| 沈丘县| 楚雄市| 昭通市| 筠连县| 平江县| 自贡市|