asp.net中datagrid获取checkbox选中行的值
1个回答
展开全部
测试了一下,可以实现的。你的错误应该是,绑定事件没有放在!IspostBack里面,这样按钮点击后,在Page_load又会重新绑定,当然会把你之前选择的清空掉。
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
SectionDataList.DataSource = BLL.personnel.EmployeesBLL.GetAllList();
SectionDataList.DataBind();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
foreach (DataListItem item in SectionDataList.Items)
{
CheckBox checkbox = (CheckBox)item.FindControl("cbSection");
if (checkbox.Checked == true)
{
Response.Write("aaa");
}
}
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
SectionDataList.DataSource = BLL.personnel.EmployeesBLL.GetAllList();
SectionDataList.DataBind();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
foreach (DataListItem item in SectionDataList.Items)
{
CheckBox checkbox = (CheckBox)item.FindControl("cbSection");
if (checkbox.Checked == true)
{
Response.Write("aaa");
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询