我刚开始使用 Linq to sql。我正在努力将控制变量传递到删除语句中。有人可以看看这个并指出我正确的方向吗?
protected void Delete_Click(object sender, EventArgs e)
{
NorthwindDataContext db = new NorthwindDataContext();
foreach (GridViewRow row in GridView1.Rows)
{
if (((CheckBox)row.FindControl("CheckBox1")).Checked)
{
string prod_id = row.FindControl("lbl_id").ToString();
Product product = (from p in db.Products
where p.ProductID == int.Parse(prod_id) // <-- I get conversion errors here!!
select p).Single();
db.Products.DeleteOnSubmit(product);
db.SubmitChanges();
}
}
ShowProducts();
}