CheckBox控件在GridView ASP.net中不起作用 [英] CheckBox control is not working in GridView ASP.net

查看:60
本文介绍了CheckBox控件在GridView ASP.net中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  protected   void  Button1_Click(对象发​​件人,EventArgs e)
{
for int i = 0 ; i < GridView1.Rows.Count; i ++)
{
bool isChecked =((CheckBox)GridView1.Rows [i] .FindControl( CheckBox1))。已检查;
if (isChecked)
{
Response.Write( True \t);
}
else
{
Response.Write( False \t);
}
}
}





< img src =''http://s8.postimage.org/nnj0sgy5d/chk1.jpg''border =''0''alt =chk1/> ;

解决方案



它会帮助你。

不填写gridview in page_load

如果需要填写然后使用

  if (!IsPostBack){  //  填充代码//}  





  protected   void  Button1_Click( object  sender,EventArgs e)
{
foreach (GridViewRow di in Gridview1.Rows)
{
if (di.RowType == DataControl RowType.DataRow)
{
CheckBox cb =(CheckBox)di.FindControl(& quot; CheckBox1& quot;);
布尔 isChecked = cb.Checked;
if (isChecked)
{
Response.Write( True \t);
}
else
{
Response.Write( False \t);
}
}
}
}



保持编码


试试这个..

  bool  isChecked = False; 

受保护 void Button1_Click(对象发​​件人,EventArgs e)
{
for int i = 0 ; i& lt; GridView1.Rows.Count; i ++)
{isChecked =(CheckBox)GridView1.Rows [i] .FindControl( &安培; QUOT; CheckBox1&安培; QUOT;))经过;
if (isChecked)
{
break ;
}

}
如果(isChecked)
{
Response.Write(< span class =code-string> True \t);
}
else
{
Response.Write( False \t);
}
}


  protected   void  Button1_Click( object  sender,EventArgs e)
{
bool isChecked = false ;
foreach (DataRow row in GridView1.Rows)
{
CheckBox CBox =(CheckBox)GridView1.Rows [row] .FindControl( CheckBox1);
if (CBox.Checked)
{
isChecked = true ;
break ;
}
}
如果(isChecked)
{
Response.Write( True);
}
else
{
Response.Write( False);
}
} < / pre >


protected void Button1_Click(object sender, EventArgs e)
    {
        for (int i = 0; i < GridView1.Rows.Count;i++ )
        {
            bool isChecked = ((CheckBox)GridView1.Rows[i].FindControl("CheckBox1")).Checked;
            if (isChecked)
            {
                Response.Write("True \t");
            }
            else
            {
                Response.Write("False \t");
            }
        }
    }



<img src=''http://s8.postimage.org/nnj0sgy5d/chk1.jpg'' border=''0'' alt="chk1" />

解决方案

Hi,
It will Help You.
do not fill gridview in page_load
if need filling then use

if(!IsPostBack){//filling code//}



protected void Button1_Click(object sender, EventArgs e)
    {
foreach (GridViewRow di in Gridview1.Rows)
       {
           if (di.RowType == DataControlRowType.DataRow)
           {
               CheckBox cb = (CheckBox)di.FindControl(&quot;CheckBox1&quot;);
               Boolean isChecked = cb.Checked;
               if (isChecked)
               {
                   Response.Write("True \t");
               }
               else
               {
                   Response.Write("False \t");
               }
           }
       }
}


Keep Coding


try this..

bool isChecked=False;

protected void Button1_Click(object sender, EventArgs e)
    {
        for (int i = 0; i &lt; GridView1.Rows.Count;i++ )
        {         isChecked=(CheckBox)GridView1.Rows[i].FindControl(&quot;CheckBox1&quot;)).Checked;
            if (isChecked)
            {
                break;
            }
           
        }
          if (isChecked)
            {
                Response.Write("True \t");
            }
            else
            {
                Response.Write("False \t");
            }
    }


protected void Button1_Click(object sender, EventArgs e)
    {
       bool isChecked=false;
        foreach(DataRow row in GridView1.Rows)
        {             
            CheckBox CBox=(CheckBox)GridView1.Rows[row].FindControl("CheckBox1");
            if (CBox.Checked)
            {
                isChecked=true;
                break;
            }
          }
          if (isChecked)
            {
                Response.Write("True");
            }
            else
            {
                Response.Write("False");
            }
    }</pre>


这篇关于CheckBox控件在GridView ASP.net中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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