多用户控制和客户端ID asp.net JS
问题描述:
我下面的帖子:多用户控制和客户端ID asp.net JS
http://mosesofegypt.net/post/GridView-with-Select-All-CheckBox-using-JQuery.aspx
建立在asp.net GridView的复选框列与选择/取消选择所有功能。 就我而言,gridview和javascript(JQuery)代码位于动态加载用户控件的内部,并且该用户控件有多个实例。选择/取消选择功能仅在页面上创建的最后一个用户控件中起作用。 换句话说,js脚本中的gvProducts.ClientId只知道最后一个gridview。 任何想法如何才能在其他用户控件(即除最后一个)之外的GridView的ClientIds引用? 任何帮助将不胜感激。
编辑:这个问题基本上和在这篇文章中提到的一样:Multiple user control instances and ClientID in JS 但是没有帮助的答案。
感谢, 阿里
答
你可以添加一个的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