ASP:Gridview分页复选框列不显示哪个复选框被选中
创始人
2024-09-20 00:31:02
0

可以使用以下方法来解决这个问题:

  1. 在Gridview的每个复选框列中添加一个隐藏域。

  2. 在Gridview的RowDataBound事件中获取Gridview中的每个行,并使用以下代码来确定哪个复选框被选中:

     protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
     {
         if (e.Row.RowType == DataControlRowType.DataRow)
         {
             //获取复选框列的隐藏域
             HiddenField hf = e.Row.FindControl("HiddenField1") as HiddenField;
             //获取复选框控件
             CheckBox cb = e.Row.FindControl("CheckBox1") as CheckBox;
    
             //判断复选框是否被选中
             if (cb.Checked)
             {
                 //将选中的行的行索引添加到隐藏域中
                 hf.Value = GridView1.DataKeys[e.Row.RowIndex].Value.ToString();
             }
         }
     }
    
  3. 在Gridview中的每个删除按钮中使用以下代码来获取选中的行:

     protected void btndelete_Click(object sender, EventArgs e)
     {
         foreach (GridViewRow row in GridView1.Rows)
         {
             //获取复选框列的复选框控件
             CheckBox cb = row.FindControl("CheckBox1") as CheckBox;
             //获取复选框列的隐藏域
             HiddenField hf = row.FindControl("HiddenField1") as HiddenField;
    
             //判断复选框是否被选中
             if (cb.Checked)
             {
                 //使用隐藏域中的值来删除选中的行
                 int id = Convert.ToInt32(hf.Value);
                 //执行删除操作
             }
         }
     }
    

这样,就可以解决Gridview分页复选框列不显示哪个复选框被选中的问题。

相关内容

热门资讯

透视神器!aapoker怎么设... 透视神器!aapoker怎么设置抽水(透视)aapoker透视脚本,可靠教程(有挂详情)一、aapo...
透视攻略!aapoker怎么控... 透视攻略!aapoker怎么控制牌(透视)aapoker透视插件,可靠教程(有挂辅助)1、首先打开a...
透视透视挂!aapoker插件... 透视透视挂!aapoker插件(透视)aapoker发牌逻辑,可靠教程(有挂辅助)1、aapoker...
透视脚本!aapoker破解侠... 透视脚本!aapoker破解侠是真的吗(透视)aapoker ai插件,黑科技教程(有挂工具);1、...
透视脚本!aapoker怎么设... 透视脚本!aapoker怎么设置提高好牌几率(透视)aapoker透视脚本下载,揭秘攻略(有挂攻略)...
透视ai代打!aapoker免... 透视ai代打!aapoker免费透视脚本(透视)aapoker辅助怎么用,2025新版总结(有挂方法...
透视总结!aa poker透视... 透视总结!aa poker透视软件(透视)aapoker破解侠是真的吗,透明教程(有挂脚本);1、任...
透视好牌!aapoker透视方... 透视好牌!aapoker透视方法(透视)aapoker插件下载,AA德州教程(有挂解说)aapoke...
透视辅助!aapoker辅助器... 透视辅助!aapoker辅助器怎么用(透视)aapoker安装包怎么使用,解密教程(有挂黑科技)aa...
透视透视!aa poker辅助... 透视透视!aa poker辅助(透视)aa poker辅助,高科技教程(有挂方法);透视透视!aa ...