I want to get the or of all checkboxes in a gridview after a button click. 或 。
But none of the checkbox is returning even if i check them. 。
Please write me the reason and solution.Thanks in Advance
protected void Button1_Click(object sender, EventArgs e)
{
foreach(GridViewRow r in GridView1.Rows)
{
Boolean b = ((CheckBox)GridView1.Rows[r.RowIndex].Cells[0].FindControl("cbox")).Checked;
Response.Write(b);
}
}
The problem is likely that you are Rebinding the data on page load (which happens before control events).
Try wrapping your binding methods in
If (!IsPostBack)
{
//Load Data
}
EDIT:
Useful link is useful: http://msdn.microsoft.com/en-us/library/ms178472.aspx#lifecycle_events
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.