2011-11-10 20 views
2

我的所有jQuery函數都在第一次加載頁面時完美工作,之後我執行一個回發,導致爲GridView填充rowfilter並綁定Grid再次基於rowfilter。我的GridView完全由代碼構建,並以表格的形式呈現。在此PostBack之後,函數mouseover,mouseout並單擊我表中的錶行不再工作。GridView上的jQuery函數在頁面回傳後停止工作(鼠標懸停,單擊)

我把我的jQuery函數放在document.ready函數中。我回發,這是添加到行的HTML之前還注意到:

<tr jQuery1320916="3"> 

所以基本上在每行(3),並在它的前面用jQuery一些隨機數結束的序列。回發之後,這將從行中刪除。

這裏是我的jQuery代碼的一部分(第一個點擊功能還是回傳後的作品,但在GridView控件的功能不再):

$(document).ready(function(){ 
     //start click function select all 
     $('input[id$="SelectDeselectAllBox"]').click(function(){    
     //start if 
     if($(this).is(':checked')){ 
      $(this).parent().parent().parent().parent().children().find('input:checkbox').attr('checked',true).closest('tr').addClass('SelectedRow') 
     }else{ 
      $(this).parent().parent().parent().parent().children().find('input:checkbox').attr('checked',false).closest('tr').removeClass('SelectedRow')}; 
     //end if 

     //end click function select all 
      }); 


     //highligth hovered row 
      $('table[id^=taskgrid] tbody tr').mouseover(function() { 
       $(this).addClass('HightlightRow'); 
      }).mouseout(function() { 
       $(this).removeClass('HightlightRow'); 
      });    

     //end document ready 
     }); 

我失去了一些東西,在此先感謝。

我發現jQuery不會用這種方法找到我的GridView了:

$( '表[ID^= taskgrid] TBODY TR'),如果我填寫taskgrid總ID則確實有效。但這不適合我。

//is everthing checked? start if 
if($(this).parent().find('input:checkbox:not(:checked)').length == 0){ 
    $(this).parent().parent().parent().parent().find('input:checkbox:first').attr('checked',true) 
    }else{ 
    $(this).parent().parent().parent().parent().find('input:checkbox:first').attr('checked',false)}; 
//end if 
+0

檢查此問題:http://stackoverflow.com/questions/256195/jquery-document-ready-and-updatepanels –

+0

我沒有在我的解決方案中使用UpdatePanel,引用該問題的答案:「PageRequestManager是一個JavaScript對象,如果更新面板位於頁面上,則該對象自動可用。「 – user1039394

回答

1

的問題是,您使用的是「開始與」選擇:

$('table[id^=taskgrid] tbody tr') 

這是更好地使用選擇的ASP.NET Web窗體生成的ID「結尾」。假設你的GridView ID爲「taskgrid」,請嘗試使用以下選擇:

$('table[id$="taskgrid"] tbody tr') 

如果你是針對幾個表元素和「taskgrid」爲ID的只是一部分,你可以使用「包含」選擇:

$('table[id*="taskgrid"] tbody tr') 
+0

問題是我在一個頁面上有多個gridviews,Gridviews的總數可能不同,我給網格分配一個由taskgrid_ +網格名稱(每個網格中不同)的ID組成的ID。當我偶然到$('table [id * =「taskgrid」] tbody tr')時,搜索包含taskgrid的ID的表。在這之後,鼠標懸停和點擊功能可以正常工作,但是用於檢查單擊網格中所有複選框是否被選中的以下功能會檢查該網格視圖中的選擇/取消選擇全部複選框。我添加了上面的功能。 – user1039394

+0

然後去「包含」選擇器 - > $('table [id * =「taskgrid」] tbody tr') – tpeczek

+0

我的確幫助了我原來的問題,所以非常感謝! – user1039394

相關問題