iterate through ALL rows in a GridView

前端 未结 1 1784
执念已碎
执念已碎 2021-01-13 14:43
 
 
 

        
相关标签:
1条回答
  • 2021-01-13 15:16

    Look at your logic - you only have the one checkbox. You're unchecking and checking the same control in the employee loop. Does each grid row have a checkbox that should be selected based on the condition the id exists in the employee list?

     foreach (GridViewRow row in gv.Rows)
        {
            Label Id = row.FindControl("lblId") as Label;
            var result = Employee.GetEmployeeById(Id.Text);
            if (result.Count > 0)
            {
                CheckBox chkBox = row.FindControl("chkSelected") as CheckBox;
                if (chkBox != null)
                {
                    chkBox.Checked = result.Any(x => x.Id.ToString() == Id.Text);
    
                }
            }
    
        }
    
    0 讨论(0)
提交回复
热议问题