简体   繁体   中英

Accessing the Checkbox inside Datagrid on Button click Asp.net

  bool checked1 = (datagrid1.FindControl("CheckBox1") as System.Web.UI.WebControls.CheckBox).Checked;

I am getting Object reference not set to an instance of an object.

How do i access from inside the DataGrid whether the CheckBox is Check Or Not?

NOTE: The CheckBox is inside the HeaderTemplate

You've to iterate across the DataGridItems

foreach( DataGridItem di in datagrid1.Items )
    {
        CheckBox chkBx = (CheckBox)di.FindControl("CheckBox1") ;
        if( chkBx !=null && chkBx.Checked )
        {
            //isChecked
        }
    }

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM