焚寂六月 2017-05-10 04:04 采纳率: 64.7%
浏览 2215

CheckBox被选中但在后台代码调试中一直为false


protected void bntDelete_Click(object sender, EventArgs e)
{
int count = 0;
string id = "";
string adminID;

    foreach (GridViewRow gr in this.GridView1.Rows)
    {
        CheckBox chk = (CheckBox)gr.Cells[0].FindControl("cbSelect");
        if (chk.Checked)
        {
            adminID = gr.Cells[1].Text;
            if (0 == count)
            {
                id = "(" + int.Parse(adminID);
            }
            else
            {
                id += "," + int.Parse(adminID);
            }
            count++;
        }
    }
    id += ")";

    if (0 == count)
    {
        Response.Write("<script>alert('请选择管理员!');location.href = 'AdminInfoManagement.aspx';</script>");
        return;
    }
    else
    {
        Administrator admin = new Administrator();
        if (admin.DeleteAdminInfo(id))
        {
            Response.Write("<script>alert('删除成功!');location.href = 'AdminInfoManagement.aspx';</script>");
        }
        else
        {
            Response.Write("<scrip>alert('" + admin.ErrorMessage + "');location.href = 'AdminInfoManagement.aspx';</scrip>");
        }
    }
    this.GridView1.DataBind();
    return;
}

    前台代码就是这样的:
    <asp:TemplateField HeaderText="选择">
                      <ItemTemplate>
                          <asp:CheckBox ID="cbSelect" runat="server" />
                      </ItemTemplate>
                      <ItemStyle Width="20px" HorizontalAlign="Center" VerticalAlign="Middle" />
                    </asp:TemplateField>
  • 写回答

1条回答 默认 最新

  • 赵大笨笨 2017-05-10 04:43
    关注

    应该把你前台代码贴出来。
    1.看看checkbox是不是设置了value属性。
    2.可以通过jquery,当你判断checked之后把value设置成true。
    3.如果都不可以,你改改id试试,是不是id和其他重复了

    评论

报告相同问题?

悬赏问题

  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值