选择框checkbox

选择框checkbox

<!DOCTYPE html>
<html>
<head>
  <style>
  a{display:inline-block;}
  </style>
  <script src="http://libs.useso.com/js/jquery/1.7.2/jquery.min.js"></script>
</head>
<body>
<a data-command="check-true">全选</a>
<a data-command="check-false">反选</a>
<input type="checkbox">
<input type="checkbox">
<input type="checkbox">
<input type="checkbox">
 <script>
$(function(){
    $('[data-command="check-true"]').click(function(){
        $('input[type="checkbox"]').attr("checked",true)
    });
    $('[data-command="check-false"]').click(function(){
        $('input[type="checkbox"]').each(function(){
            $(this).attr("checked",!$(this).attr("checked"));
        });
    })
});
</script>
</body>
</html>

 

转载于:https://www.cnblogs.com/wzzl/p/5390831.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
您可以遵循以下步骤来实现您的要求: 1. 在GridView中添加一个TemplateField,将其中的ItemTemplate设置为CheckBox控件,并将CheckBox的Value属性设置为绑定的数据项的ID。例如: ```html <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false"> <Columns> <asp:TemplateField HeaderText="选择"> <ItemTemplate> <asp:CheckBox ID="CheckBox1" runat="server" Value='<%# Eval("ID") %>' /> </ItemTemplate> </asp:TemplateField> <asp:BoundField DataField="Name" HeaderText="名称" /> <asp:BoundField DataField="Age" HeaderText="年龄" /> </Columns> </asp:GridView> ``` 2. 在按钮的Click事件中,遍历GridView中的所有行,查找被选中的CheckBox控件,并获取其Value属性值,将其存储到一个字符串变量中。例如: ```csharp protected void Button1_Click(object sender, EventArgs e) { string selectedIds = ""; foreach (GridViewRow row in GridView1.Rows) { CheckBox checkBox = row.FindControl("CheckBox1") as CheckBox; if (checkBox != null && checkBox.Checked) { string id = checkBox.Attributes["Value"]; selectedIds += id + ","; } } if (!string.IsNullOrEmpty(selectedIds)) { selectedIds = selectedIds.TrimEnd(','); // 跳转到下一个页面,并将选中的ID作为参数传递过去 Response.Redirect("NextPage.aspx?ids=" + selectedIds); } } ``` 3. 在下一个页面(例如NextPage.aspx)的Page_Load事件中,获取传递过来的选中的ID,并进行相应的处理。例如: ```csharp protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { string selectedIds = Request.QueryString["ids"]; if (!string.IsNullOrEmpty(selectedIds)) { string[] ids = selectedIds.Split(','); foreach (string id in ids) { // 根据ID进行相应的处理 } } } } ``` 希望这些步骤对您有所帮助!

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值