Click here to Skip to main content
15,895,667 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
C#
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" />
Posted

Hi,
It will Help You.
do not fill gridview in page_load
if need filling then use
C#
if(!IsPostBack){//filling code//}


C#
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
 
Share this answer
 
try this..
C#
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");
            }
    }
 
Share this answer
 
v2
Comments
PRAKASH_N 7-Dec-12 4:54am    
no..not working
C#
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>
 
Share this answer
 
Comments
PRAKASH_N 7-Dec-12 4:56am    
Error: Argument '1': cannot convert from 'System.Data.DataRow' to 'int'
choudhary.sumit 7-Dec-12 5:00am    
use only row instead of Rows[row] in "(CheckBox)GridView1.Rows[row].FindControl("CheckBox1");"

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900