2015-09-30 30 views
0

我創建了一個gridview並在項目模板中添加了一個複選框。這個網格與DataKey (primary key)一起有幾列。由於性能提高,此網格將根據頁面點擊次數,在每次頁面更改時獲取下一組recrod。這樣就完成了。在自定義分頁時在gridview中保留複選框

現在,當用戶選擇第一頁中的複選框,然後轉到第2頁並返回到第一頁時,用戶將看不到像用戶之前做的那樣檢查複選框。

那麼,當用戶移動頁面到頁面時,是否有一種很好的方式來保持複選框?

該複選框用作選擇稍後可被網格外按鈕刪除的行的標誌。

+0

**複選框**做了什麼?它是否執行任何類型的服務器操作** oncheckedchanged **事件,如更新單個或一組字段? – Prabhat

+0

用戶想要選中複選框,然後通過單擊網格外的按鈕執行刪除操作。這就像Gmail上的功能一樣。 – amir

回答

0

既然你收到一組新的選擇尋呼每一次,我建議採取下列措施:

創建通過javascript只要選擇一個複選框,將增加列出datakey,進而將其刪除的array[]對象如果複選框被取消選擇。事情是這樣的:

var selectedDataKeys = []; 

$('.checkboxclass').on('change', function() { 

    // Considering you assign the data key as id for the checkbox otherwise implement a way to retrieve the id. 
    var dataKey = $(this).prop('id'); 

    // Determine if the dataKey is in the selected data keys array 
    var isContained = (selectedDataKeys.indexOf(dataKey) > -1); 

    if($(this).is(':checked')) { 
     // If is contained is false - add to the array 
     if (!isContained) 
     selectedDataKeys.push(dataKey); 
    } else { 
     // If is contained is true - remove to the array 
     if (isContained){ 
     selectedDataKeys = $.grep(selectedDataKeys, function(value) { 
      return value != dataKey; 
     }); 
     } 
    } 
}); 

從客戶端用戶這一點,將會有選擇的項目的活動列表,現在它的你來使用該列表來操作你的網格顯示頁面。通過將網格顯示中的所有項目與selectedDataKeys數組進行比較或者發送這些密鑰並執行比較服務器端,可以修改文檔上的顯示。

希望這會有所幫助。

相關問題