private void BtnDelete_Click(object sender, RoutedEventArgs e) { //获取鼠标选择的索引 int num = dgUsers.SelectedIndex; if (num < 0) { MessageBox.Show("请选择要删除的行!"); } else { //获取选中行 AttendanceData user = (AttendanceData)dgUsers.SelectedValue; if (MessageBox.Show("是否删除" + user.Name + "的信息", "提示", MessageBoxButton.YesNo) == MessageBoxResult.Yes) { //删除数据 if (bll.Delete(user.ID, 0)) { MessageBox.Show("删除" + user.Name.Trim() + "成功"); } } //加载数据 LoadData(); } }