2010-05-03 48 views

回答

0

如果你是使用jQuery在你的框架只是使用jQuery.getJSON()更新狀態

1

這可能是更容易,它似乎。

首先讓我們得到到GridView(呈現爲一個表)

var t = document.getElementById('<% =GridView1.ClientID %>'); // use your gridview's id 

參考然後我們需要一個複選框列表

var tableInputs = t.getElementsByTagName('input'); // gets all input elements within the table 
var chkList = []; // array where we'll keep track of marked checkboxes 

for(var i=0; i<tableInputs.length; i++) { 

// see if it's a checkbox and whether or not it's checked 
    if (tableInputs[i].type.match(/checkbox/i) && tableInputs[i].checked) { 
     // it is and it is, so add it to the list 
     chkList.push(tableInputs[i]); 
    } 
} 

現在你可以使用複選框來獲得參考到特定的行並找到隱藏的元素

var fields; 
var tr = null; 

for (var j = 0; j < chkList.length; j++) { 
    // look up the heirarchy until you find the table row 
    tr = chkList[j].parentNode; 
    while (!tr.nodeName.match(/tr/i)) { 
     tr = chkList[j].parentNode; 
    } 

    // repeat the checkbox process for hidden fields 
    fields = tr.getElementsByTagName('input'); // all inputs in the same row 
    for (var k = 0; k < fields.length; k++) { 
     // see if it's a hidden field 
     if (fields[k].type.match(/hidden/i)) { 
      //TODO: here's a hidden field, do something 

     } 
    } 
    tr = null; 
} 

我並不總是記得標記nam es區分大小寫,所以我默認爲不區分大小寫的正則表達式。

+0

+1對於非jQuery的答案。非常感謝! – 2011-05-16 03:31:20

0

如果您正在使用jQuery

var values = []; 
$.each($("#gridid .hiddenfields"), function(i, item) { 
    values.push($(item).val()); 
}); 

這將讓你與數組中的值,也隱藏字段必須是類=「hiddenfields」,希望這有助於。

相關問題