你可以添加一個的CssClass到GridView和基本的jQuery選擇過這一點。
腳本:
<script type="text/javascript">
$(function() {
$(".t th input:checkbox").click(function() {
var $checkbox = $(this).closest('table').find(':checkbox:not(:first)');
$checkbox.attr('checked', $(this).attr('checked'));
});
});
</script>
2表具有相同的類名:
<table class="t">
<tr>
<th align="left" scope="col">Category</th>
<th align="left" scope="col">Product</th>
<th align="right" scope="col">Unit Price</th>
<th align="left" scope="col">Supplier</th>
<th scope="col">
<input type="checkbox" name="select-all" />
</th>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td><input type="checkbox" /></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td><input type="checkbox" /></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td><input type="checkbox" /></td>
</tr>
</table>
<br /><br /><br />
<table class="t">
<tr>
<th align="left" scope="col">Category</th>
<th align="left" scope="col">Product</th>
<th align="right" scope="col">Unit Price</th>
<th align="left" scope="col">Supplier</th>
<th scope="col">
<input type="checkbox" name="select-all" />
</th>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td><input type="checkbox" /></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td><input type="checkbox" /></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td><input type="checkbox" /></td>
</tr>
</table>
感謝fehays,但這樣CssClass屬性將適用於網頁上的所有GridView的和選擇/取消選擇所有的意志適用於所有的gridviews。我需要能夠在單個gridview上工作。還有什麼建議? – Ali 2010-11-30 16:58:47