通过分页查找Grdiview中Checkbox的状态
这是我用来查找是否在 gridview 中选中任何复选框的代码,
if($("table tr td:first-child input:checkbox:checked").length ==0)
{
alert("Select atleast one event to delete");return false ;
}
if(confirm('Are you sure! you want to delete the selected events(s)?'))
return true;
else
return false ;
我在第一页中选择一个复选框,然后导航到第二页,然后单击“删除”,它会抛出“选择至少一个要删除的通道”。哪个不应该!
没有分页它工作正常。有什么见解可以通过分页来实现这一点吗?
This is the code that i use to find whether any checkbox is checked in gridview
if($("table tr td:first-child input:checkbox:checked").length ==0)
{
alert("Select atleast one event to delete");return false ;
}
if(confirm('Are you sure! you want to delete the selected events(s)?'))
return true;
else
return false ;
i select a checkbox in the first page and i navigate to the 2nd page and i click "Delete", it throws "select atleast one Channel to delete". Which Shouldn't!
Without paging it works fine. Any insight to implement this with paging?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
一旦您导航到下一页,首先选择的复选框的 DOM 元素就不再显示,因此脚本将不知道它们。
如果您希望通过页面保留复选框状态,则需要在页面更改时缓存状态。请记住,这些也不会在回发中传递。
As soon as you navigate to the next page the DOM elements for the checkboxes selected first are not displayed anymore, and therefore the script will not know about them.
You will need to cache the state at a page change if you wish to preserve the checkbox state through pages. Remember that these won't be passed in a postback either.
这是因为当显示第二页时,第一页中的复选框不会呈现。
在执行删除记录等关键操作时,最好让用户知道所有记录都被删除。
您的方法的问题是,如果用户位于另一个页面,则他将无法找到选择执行操作的记录。所以我认为这不是一个很好的可用性功能。
This is because the checkboxes in the first page are not rendered when the second page is shown.
It would be better when doing critical actions like deleting records the user be aware of which all records are being deleted.
The issue with your approach is that the user won't be able to find the records which are selected for action if he is in another page. So it won't be a good usability feature in my opinion.
不要检查复选框检查值,而是尝试将它们保存在会话或其他内容中,然后尝试循环它们并检查这些值。可能会将它们存储在某种数组中。上面的用户是对的,当你没有在屏幕上渲染控件时,你会得到对象空错误。
Instead of checking checkbox checked value , try saving them in session or something and try looping through them and check for those values. May be store them in somekind of array. Above users are right , when you dont have control rendered on the screen , you will get object null error.
从一页移动到另一页时,您可以在 JavaScript 中手动维护选中复选框的状态。
在最终删除方法中,检查可用状态数据中是否有任何选中的值。
You can manually maintain status of checked checkboxes in javascript while moving from one page to other.
And on final delete method, check for the any checked value in your available status data.