for(int i=0;i<this.dg.Items.Count;i++)
{
CheckBox chkbox=(CheckBox)(this.dg.Items[i].FindControl("boardid"));
if(chkbox.Checked)
{
}
}

解决方案 »

  1.   

    private void delButton_Click(object sender, System.EventArgs e)
    {
    System.Web.UI.WebControls.CheckBox checkBox;
    for( int i = 0; i < DataGrid1.Items.Count; i ++ )
    {
    //查找CheckBox控件
    checkBox = (CheckBox)DataGrid1.Items[i].FindControl("CheckBox1"); if(checkBox!=null && checkBox.Checked)
    {
    checkBoxID = DataGrid1.Items[i].Cells[1].Text; CB_ItemName = DataGrid1.Items[i].Cells[2].Text;

    delDataGrid();
    }

    }
    //重新绑定DataGrid
    BindData();

    }
    private void delDataGrid()
    { SqlConnection sqlConnection1 = new SqlConnection( material.source ); sqlConnection1.Open();//打开数据库连接

    //Sql删除语句
    string strDel = "DELETE FROM AcceptMaterialTwo WHERE ItemNum='"+checkBoxID+"'";

    System.Data.SqlClient.SqlCommand sqlDeleteCommand1 = new System.Data.SqlClient.SqlCommand( strDel, sqlConnection1 );

    sqlDeleteCommand1.ExecuteNonQuery();

    sqlConnection1.Close(); // 关闭数据库连接
    }