当它被选中的复选框总是返回true [英] Checkbox always returns true when it is unchecked

查看:147
本文介绍了当它被选中的复选框总是返回true的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有嵌套的GridView 最后的GridView 复选框

在检查条件的复选框无论是选中或取消选中

 的foreach(在GridView1.Rows GridViewRow GVR)
{
       GridView控件GridView2 = gvr.FindControl(GridView2)作为GridView控件;
       的foreach(在GridView2.Rows GridViewRow gvr2)
       {
           GridView控件GridView3 = gvr2.FindControl(GridView3)作为GridView控件;
           的foreach(在GridView3.Rows GridViewRow gvr3)
           {
               如果(((复选框)gvr3.FindControl(CHK1))。经过)
               {
                    字符串的txt = txtKeyboard.text;
               }
           }
       }
}

即使它未被选中它会去,虽然条件


解决方案

 如果(((复选框)gvr3.FindControl(CHK1))。经过)
{
     字符串的txt = txtKeyboard.text;
}

而不是上面code只是尝试一次。

 复选框CHK1 = gvr3.Cells [0] .Controls [0]为复选框;
  如果(chk1.checked ==真)
  {
      字符串的txt = txtKeyboard.text;
  }

在这里你需要设置 0

的单元格值和控制值就地

I have nested Gridview and the last Gridview has Checkbox.

the condition in checking the Checkbox whether it is checked or unchecked

foreach (GridViewRow gvr in GridView1.Rows)
{
       GridView GridView2= gvr.FindControl("GridView2") as GridView;
       foreach (GridViewRow gvr2 in GridView2.Rows)
       {
           GridView GridView3= gvr2.FindControl("GridView3") as GridView;
           foreach (GridViewRow gvr3 in GridView3.Rows)
           {
               if(((CheckBox)gvr3.FindControl("chk1")).Checked)
               {
                    string txt = txtKeyboard.text;
               }
           }
       }
}

even though it is unchecked it will go though the condition

解决方案

if(((CheckBox)gvr3.FindControl("chk1")).Checked)
{
     string txt = txtKeyboard.text;
}

instead of above code just try once

  CheckBox chk1 = gvr3.Cells[0].Controls[0] as CheckBox;
  if(chk1.checked==true)
  {
      string txt = txtKeyboard.text;
  }

here you need to set cell value and control value inplace of 0

这篇关于当它被选中的复选框总是返回true的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆