[英]Template checkbox checked property is getting false in Gridview for delete operation
I have used template CheckBox in gridview for multiple rows deletion, when I select multiple rows by selecting the CheckBox and perform the delete operation it seems to be selected CheckBox is not returning true on the code below. 我在gridview中使用模板CheckBox删除多行,当我通过选择CheckBox选择多行并执行删除操作时,它似乎被选中CheckBox在下面的代码中没有返回true。
protected void Button6_Click(object sender, EventArgs e) { protected void Button6_Click(object sender,EventArgs e){
foreach (GridViewRow row in GridView1.Rows)
{
LinkButton ch = new LinkButton();
ch = (LinkButton)row.FindControl("l1");
id = Convert.ToInt16(ch.CommandArgument);
CheckBox chs = new CheckBox();
chs = ((CheckBox)row.FindControl("c1"));
if (chs.Checked == true)
{
DeleteSelected(id);
}
}
}
private void DeleteSelected(short id)
{
var ch = from a in empd.Employees where (a.ID == id) select a;
empd.Employees.DeleteAllOnSubmit(ch);
empd.SubmitChanges();
display_emp();
}
Could someone please assist me why CheckBox
is not returning true value in calling function. 有人可以帮我解释为什么CheckBox
没有在调用函数中返回真值。
Well now I have fixed the connection everything, please just refresh the database.Please get the web application in the below link. 那么现在我已经修复了所有连接,请刷新数据库。请在下面的链接中获取Web应用程序。
http://www.ziddu.com/download/20716096/WebApplication.zip.html Please help me on why selected checkbox are not returning true in the code. http://www.ziddu.com/download/20716096/WebApplication.zip.html请帮我解释为什么选中的复选框在代码中没有返回true。
Details: Add if(IsPostback) at the start otherwise it just resets your grid controls. 详细信息:在开始时添加if(IsPostback),否则它只会重置您的网格控件。 Example below 以下示例
Solution: 解:
if (!IsPostBack)
{
empd = new Employee_DetailsDataContext();
empd.Connection.ConnectionString = ConfigurationManager.ConnectionStrings["DemosConnectionString1"].ConnectionString;
display_emp();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.